com.tomgibara.pronto.config
Interface ConfigPolicy

All Known Implementing Classes:
DefaultConfigPolicy

public interface ConfigPolicy

Implementations of this interface control the operational parameters of config objects. Implementations are not required to return consistent values between method calls. In-short, policies may be dynamic. It is expected that most policy implementations will extends the default implementation. Policies must be safe for concurrent access.

Author:
Tom Gibara

Method Summary
 java.lang.Object defaultForClass(java.lang.Class clss)
          This method should return a default property value for the specified class.
 long getMinReadPeriod()
          This method is called to determine the minimum period of time in milliseconds which must elapse before a config will consider refreshing configuration information.
 boolean isCachingEager()
          This method is called to control whether the objects converted from configuration properties may be cached even if no class loader has been specified on a config.
 boolean isDefaultsCached()
          This method is called to determine whether values created by the defaultForClass method may be cached for subsequent property requests.
 boolean isExceptionLogged()
          Whether exceptions generated by the configuration source when accessing properties should be logged.
 boolean isExceptionThrown()
          Whether exceptions generated by the configuration source when accessing properties should be thrown from the interface accessor methods.
 boolean isTimestampNewer(long newTimestamp, long oldTimestamp)
          This method is called to identify whether the change in the timestamp associated with a set of configuration properties represents a change in the properties.
 java.lang.String propertyFromMethod(java.lang.String methodName)
          This method defines the mapping of method names on an interface to property names in the configuration.
 

Method Detail

getMinReadPeriod

long getMinReadPeriod()
This method is called to determine the minimum period of time in milliseconds which must elapse before a config will consider refreshing configuration information. Returning very small values from this method may result in noticably reduced performance.

Returns:
the least time between successive checks for property changes in milliseconds

isTimestampNewer

boolean isTimestampNewer(long newTimestamp,
                         long oldTimestamp)
This method is called to identify whether the change in the timestamp associated with a set of configuration properties represents a change in the properties. For example, some systems may exhibit unstable timestamps for resources which might result in excessive re-evaluation of configuration properties. For such a system a sensible policy might be to consider only sufficiently large differences as indicators of possible change.

Parameters:
newTimestamp - the latest timestamp reported by a ConfigSource
oldTimestamp - the previous timestamp reported by a ConfigSource
Returns:
true if the timestamps indicate that the properties may have changed.

isExceptionThrown

boolean isExceptionThrown()
Whether exceptions generated by the configuration source when accessing properties should be thrown from the interface accessor methods.

Returns:
true if exceptions should be thrown, false if null values are returned

isExceptionLogged

boolean isExceptionLogged()
Whether exceptions generated by the configuration source when accessing properties should be logged.

Returns:
true if exceptions should be logged, false otherwise

propertyFromMethod

java.lang.String propertyFromMethod(java.lang.String methodName)
This method defines the mapping of method names on an interface to property names in the configuration. This method may return a name which contains dots for XXXing .

Parameters:
methodName - the name of a method being invoked
Returns:
the name of the corresponding configuration property

defaultForClass

java.lang.Object defaultForClass(java.lang.Class clss)
This method should return a default property value for the specified class. This value will be used when a non-existent property is requested via an accessor method on an interface. It is expected that in most cases this method will return null, however, it must return non-null values for primitive classes, ie. those classes for which clss.isPrimitive() returns true.

Parameters:
clss - the return type of an accessor method
Returns:
the default value for the specified class

isDefaultsCached

boolean isDefaultsCached()
This method is called to determine whether values created by the defaultForClass method may be cached for subsequent property requests.

Returns:
whether default values which have been generated by this object are apt for caching.

isCachingEager

boolean isCachingEager()
This method is called to control whether the objects converted from configuration properties may be cached even if no class loader has been specified on a config. It is expected that in most cases such caching is safe. However, it is possible that an adapted interface might be called by independent threads with different context class loaders (or by a single thread with a modified context class loader) in which case the objects returned may have incompatible types. This scenario is only possible if no class loader has been explicitly set on a config.

Returns:
whether values can be cached independently of their class loader.


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