org.webmacro.resource
Class TimedReloadContext

java.lang.Object
  extended byorg.webmacro.resource.CacheReloadContext
      extended byorg.webmacro.resource.TimedReloadContext

public class TimedReloadContext
extends CacheReloadContext

TimedReloadContext acts as an Decorator for Reload context to support cache resources that are expensive to check for change. An example is a resource fetch via the network, but could also be a file. It is constructed with a reference to another CacheReloadContext and an interval. Its shouldReload() method will pass calls to the referenced CacheReloadContext, but will take sure, that this is done only once in the specified interval. In all other cases it will return "false", to indicate, that the resource should not be reloaded.

Since:
0.96
Author:
skanthak@muehlheim.de

Constructor Summary
TimedReloadContext(CacheReloadContext reloadContext, long checkInterval)
          Construct a new TimedReloadContext decorator.
 
Method Summary
 boolean shouldReload()
          Check, whether the underlying resource should be reloaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimedReloadContext

public TimedReloadContext(CacheReloadContext reloadContext,
                          long checkInterval)
Construct a new TimedReloadContext decorator. This is just a wrapper object for another CacheReloadContext, ensuring that the shouldReload() method of the refrenced reload context is only called once per checkInterval milliseconds.

Parameters:
reloadContext - reload context to wrap around
checkInterval - interval to check for reload at most in milliseconds
Method Detail

shouldReload

public boolean shouldReload()
Check, whether the underlying resource should be reloaded. This method will simply call the shouldReload() method of the referenced reload context, except when this method was called again in the last checkInterval milliseconds. In this case, this method will simply return false.

Overrides:
shouldReload in class CacheReloadContext
Returns:
whether resource should be reloaded.