com.tomgibara.pronto.config.source
Class CachingConfigSource

java.lang.Object
  extended by com.tomgibara.pronto.config.source.CachingConfigSource
All Implemented Interfaces:
ConfigSource

public class CachingConfigSource
extends java.lang.Object
implements ConfigSource

Instances of this class wrap other ConfigSource instances and cache the values they return. Instances of this class are not safe for concurrent use, even if the underlying ConfigSource is. Wrap instances in a SynchronousConfigSource if thread safety is required.

Author:
Tom Gibara

Constructor Summary
CachingConfigSource(ConfigSource source, long ttl)
          Creates new a source which caches responses from another ConfigSource.
 
Method Summary
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          Return the cached properties field from the underlying ConfigSource.
 ConfigSource getSource()
          Returns the ConfigSource which is being cached by this object.
 long getTTL()
          The length time for which values may be cached without being refreshed.
 long lastModified()
          Return the cached lastModified field from the underlying ConfigSource.
 void setTTL(long ttl)
          Changes the length time for which values may be cached without being refreshed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingConfigSource

public CachingConfigSource(ConfigSource source,
                           long ttl)
Creates new a source which caches responses from another ConfigSource.

Parameters:
source - the configuration source to be cached, not null
ttl - the length time for which values may be cached without being refresed, not negative
Method Detail

setTTL

public void setTTL(long ttl)
Changes the length time for which values may be cached without being refreshed.

Parameters:
ttl - changes the time-to-live value, not negative

getTTL

public long getTTL()
The length time for which values may be cached without being refreshed.

Returns:
the time-to-live value, not negative

getSource

public ConfigSource getSource()
Returns the ConfigSource which is being cached by this object.

Returns:
the cached config source, never null

lastModified

public long lastModified()
                  throws java.lang.RuntimeException
Return the cached lastModified field from the underlying ConfigSource.

Specified by:
lastModified in interface ConfigSource
Returns:
the cached lastModified time
Throws:
java.lang.RuntimeException - if the field could not be read

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
                                                               throws java.lang.RuntimeException
Return the cached properties field from the underlying ConfigSource.

Specified by:
getProperties in interface ConfigSource
Returns:
the cached properties
Throws:
java.lang.RuntimeException - if the field could not be read


Copyright © 2006-2007 Tom Gibara. All Rights Reserved.