org.apache.cocoon.components.source
Class DelayedRefreshSourceWrapper

java.lang.Object
  |
  +--org.apache.cocoon.components.source.DelayedRefreshSourceWrapper
All Implemented Interfaces:
ModifiableSource, org.apache.avalon.excalibur.pool.Poolable, org.apache.avalon.excalibur.pool.Recyclable, Source, XMLizable

public final class DelayedRefreshSourceWrapper
extends java.lang.Object
implements Source, ModifiableSource, XMLizable

A wrapper around a Source that reduces the number of calls to Source.getLastModified() which can be a costly operation.

Version:
$Id: DelayedRefreshSourceWrapper.java,v 1.4 2002/02/22 07:00:13 cziegeler Exp $
Author:
Sylvain Wallez

Constructor Summary
DelayedRefreshSourceWrapper(Source source, long delay)
          Creates a wrapper for a Source which ensures that Source.getLastModified() won't be called more than once per delay milliseconds period.
 
Method Summary
 long getContentLength()
          Get the content length of the source or -1 if it is not possible to determine the length.
 org.xml.sax.InputSource getInputSource()
          Return an InputSource object to read the XML content.
 java.io.InputStream getInputStream()
          Return an InputStream object to read from the source.
 long getLastModified()
          Get the last modification time for the wrapped Source.
 java.lang.String getSystemId()
          Return the unique identifer for this source
 void recycle()
           
 void refresh()
          Force the refresh of the wrapped Source, even if the refresh period isn't over, and starts a new period.
 void toSAX(org.xml.sax.ContentHandler handler)
          Generates SAX events representing the object's state.
NOTE : if the implementation can produce lexical events, care should be taken that handler can actually be a XMLConsumer that accepts such events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelayedRefreshSourceWrapper

public DelayedRefreshSourceWrapper(Source source,
                                   long delay)
Creates a wrapper for a Source which ensures that Source.getLastModified() won't be called more than once per delay milliseconds period.
Parameters:
source - the wrapped Source
delay - the last-modified refresh delay, in milliseconds
Method Detail

getLastModified

public final long getLastModified()
Get the last modification time for the wrapped Source. The age of the returned information is guaranteed to be lower than or equal to the delay specified in the constructor.

This method is also thread-safe, even if the underlying Source is not.

Specified by:
getLastModified in interface Source
Returns:
the last modification time.

refresh

public final void refresh()
Force the refresh of the wrapped Source, even if the refresh period isn't over, and starts a new period.

This method is thread-safe, even if the underlying Source is not.

Specified by:
refresh in interface ModifiableSource

getContentLength

public final long getContentLength()
Description copied from interface: Source
Get the content length of the source or -1 if it is not possible to determine the length.
Specified by:
getContentLength in interface Source

getInputStream

public final java.io.InputStream getInputStream()
                                         throws ProcessingException,
                                                java.io.IOException
Description copied from interface: Source
Return an InputStream object to read from the source.
Specified by:
getInputStream in interface Source

getInputSource

public final org.xml.sax.InputSource getInputSource()
                                             throws ProcessingException,
                                                    java.io.IOException
Description copied from interface: Source
Return an InputSource object to read the XML content.
Specified by:
getInputSource in interface Source
Following copied from interface: org.apache.cocoon.environment.Source
Returns:
an InputSource value
Throws:
ProcessingException - if an error occurs
java.io.IOException - if an error occurs

getSystemId

public final java.lang.String getSystemId()
Description copied from interface: Source
Return the unique identifer for this source
Specified by:
getSystemId in interface Source

recycle

public final void recycle()
Specified by:
recycle in interface org.apache.avalon.excalibur.pool.Recyclable

toSAX

public final void toSAX(org.xml.sax.ContentHandler handler)
                 throws org.xml.sax.SAXException,
                        ProcessingException
Description copied from interface: XMLizable
Generates SAX events representing the object's state.
NOTE : if the implementation can produce lexical events, care should be taken that handler can actually be a XMLConsumer that accepts such events.
Specified by:
toSAX in interface XMLizable


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.