|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.sape.carbon.core.config.cache.DoubleCheckConfigurationCache
This implementation uses the infamous double-check lock to minimize the synchronization required. Multi-threaded read access to the cache will not cause contention. Adding new configurations to the cache is synchronized.
Caution: Double-check locking is not bulletproof. There is a small possibility when using optimizing compilers or multi-processor machines that stale configurations or invalid configurations are returned when multiple threads concurrently access the same configuration when that configuration is being loaded, changed, or removed.
This implementation uses 2 maps to store configuration data, an active map and a background map. When the cache is modified, the background map is updated first. Then the maps are swapped making the background map the active one. Then the background (used to be active) is updated. This is done to make use of the fact that reference assignment is atomic and prevent map from being accessed while they are being updated.
Configuration objects are cached lazily, i.e. they are cached after they are requested the first time. Once a configuration object is cached, the cache will listen for Node events on the configuration. If a node event occurs, the entire cache is cleared. This is done to prevent inconsistencies between this cache and caches internal to the configuration objects themselves in the case of nested configurations.
Copyright 2002 Sapient
Field Summary | |
private Map |
activeCache
Active cache used to return value. |
private Map |
backgroundCache
Background cache used for loading. |
private ConfigurationService |
configService
Holds the config service being cached. |
private int |
entranceCount
Holds the entrance count for re-entrant calls. |
private Map |
loadingConfigurations
Map of loaded configuration. |
private org.apache.commons.logging.Log |
log
Provides a handle to Apache-commons logger |
Constructor Summary | |
DoubleCheckConfigurationCache(ConfigurationService configService)
Constructs a new DoubleCheckConfigurationCache around the given service. |
Method Summary | |
private void |
activateBackgroundCache()
Makes the background cache active and the active cache the background. |
Configuration |
getConfiguration(String name)
Gets back a configuration with the given name. |
void |
nodeChanged(Node changedNode)
Updates the configuration cache with the new instance of the node. |
void |
nodeRemoved(String removedNodeName)
Removes a given node from the cache. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private org.apache.commons.logging.Log log
private Map activeCache
private Map backgroundCache
private ConfigurationService configService
private int entranceCount
private Map loadingConfigurations
Constructor Detail |
public DoubleCheckConfigurationCache(ConfigurationService configService)
configService
- service to provide a double-check cache for.Method Detail |
public Configuration getConfiguration(String name)
getConfiguration
in interface ConfigurationCache
name
- the name of the configuration to load
ConfigurationNotFoundException
- indicates there is
no configuration at the given namepublic void nodeChanged(Node changedNode)
nodeChanged
in interface NodeEventListener
changedNode
- the node that has been changedpublic void nodeRemoved(String removedNodeName)
nodeRemoved
in interface NodeEventListener
removedNodeName
- node to remove from the cacheprivate void activateBackgroundCache()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |