com.tomgibara.pronto.config.source
Class MapConfigSource

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

public class MapConfigSource
extends java.lang.Object
implements ConfigSource

Encapsulates a Map as a ConfigSource. At construction, the source can be instructed to cache a snapshot of the map; alternatively the source will reflect changes in the map. In either case the supplied map may be modified after it has been supplied wrapped as a ConfigSource in this way.

It is strongly recommended that only synchronized maps (maps that are safe for concurrent use such as those returned by Collections.synchronizedMap()) are used to construct sources that are not fixed.

Instances of this class are not safe for concurrent use. Wrap instances in a SynchronousConfigSource if thread safety is required.

Author:
Tom Gibara

Constructor Summary
MapConfigSource(java.util.Map<java.lang.String,java.lang.String> properties)
          Creates a new config source using properties from a supplied map.
MapConfigSource(java.util.Map<java.lang.String,java.lang.String> properties, boolean fixed)
          Creates a new config source using properties from a supplied map.
 
Method Summary
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          A map of the configuration properties supplied by this source.
 boolean isFixed()
          Whether the values returned by this config source are fixed.
 long lastModified()
          Returns the time at which the properties were last known to have changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapConfigSource

public MapConfigSource(java.util.Map<java.lang.String,java.lang.String> properties,
                       boolean fixed)
Creates a new config source using properties from a supplied map. The last-modified time for the config-source is initially taken as the time at which the source was constructed. A flag is supplied to indicate whether a snapshot of the supplied map should be taken. If the flag is true, the properties and last-modified time returned by the config-source are fixed.

Parameters:
properties - a map containing the properties for this config source
fixed - true if the properties returned by this source should not change, false otherwise.

MapConfigSource

public MapConfigSource(java.util.Map<java.lang.String,java.lang.String> properties)
Creates a new config source using properties from a supplied map. The last-modified time for the config-source is initially taken as the time at which the source was constructed. Changes to the supplied property map will be reflected in the values returned from this config source.

Parameters:
properties - a map containing the properties for this config source
Method Detail

isFixed

public boolean isFixed()
Whether the values returned by this config source are fixed.

Returns:
true if the properties returned by this source are fixed, false otherwise

lastModified

public long lastModified()
                  throws java.lang.RuntimeException
Description copied from interface: ConfigSource
Returns the time at which the properties were last known to have changed. This method must be implemented and MAY NOT return rogue values if the time is unknown. The correct behaviour in such circumstances is to return the current system time. If calculation of the time fails, the implementation is free to throw a runtime exception of its choosing.

Specified by:
lastModified in interface ConfigSource
Returns:
the time at which the properties were last known to have changed, must be positive
Throws:
java.lang.RuntimeException - if the last modified timestamp could not be generated

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
                                                               throws java.lang.RuntimeException
Description copied from interface: ConfigSource
A map of the configuration properties supplied by this source. The map returned by this method will not be modified by the config. The implementation is free to throw an unchecked exception of its choice if the properties cannot be supplied.

Specified by:
getProperties in interface ConfigSource
Returns:
the properties for this source, never null
Throws:
java.lang.RuntimeException - if the properties could not be supplied


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