org.sape.carbon.core.config.cache
Class SynchronizedConfigurationCache

java.lang.Object
  |
  +--org.sape.carbon.core.config.cache.SynchronizedConfigurationCache
All Implemented Interfaces:
ConfigurationCache, EventListener, NodeEventListener

public class SynchronizedConfigurationCache
extends Object
implements ConfigurationCache, NodeEventListener

This implementation uses a synchronized hash map to store all configurations. This is a bottleneck and may be a point of contention when many threads required configurations simultaniously.

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

Since:
carbon 1.1
Version:
$Revision: 1.11 $($Author: dvoet $ / $Date: 2003/05/05 21:21:16 $)
Author:
Douglas Voet, Oct 24, 2002

Field Summary
private  Map cache
          Holds a synchronized cache of value.
private  ConfigurationService configService
          Holds the config service being cached.
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
 
Constructor Summary
SynchronizedConfigurationCache(ConfigurationService configService)
          Constructs a new SynchronizedConfigurationCache.
 
Method Summary
 Configuration getConfiguration(String name)
          Gets back a configuration with the given name.
private  Configuration loadConfiguration(String name)
          Synchronized method to load configurations.
 void nodeChanged(Node changedNode)
          Updates the configuration cache with the new instance of the node.
 void nodeRemoved(String removedNodeName)
          Removes the node from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log
Provides a handle to Apache-commons logger


cache

private Map cache
Holds a synchronized cache of value.


configService

private ConfigurationService configService
Holds the config service being cached.

Constructor Detail

SynchronizedConfigurationCache

public SynchronizedConfigurationCache(ConfigurationService configService)
Constructs a new SynchronizedConfigurationCache.

Parameters:
configService - the service to cache
Method Detail

getConfiguration

public Configuration getConfiguration(String name)
Gets back a configuration with the given name. This will either return the configuration from the cache or load it if needed.

Specified by:
getConfiguration in interface ConfigurationCache
Parameters:
name - the name of the configuration to load
Returns:
configuration at the given name
Throws:
ConfigurationNotFoundException - indicates there is no configuration at the given name

nodeChanged

public void nodeChanged(Node changedNode)
Updates the configuration cache with the new instance of the node.

Specified by:
nodeChanged in interface NodeEventListener
Parameters:
changedNode - the node that has been changed

nodeRemoved

public void nodeRemoved(String removedNodeName)
Removes the node from the cache.

Specified by:
nodeRemoved in interface NodeEventListener
Parameters:
removedNodeName - name of the node to remove

loadConfiguration

private Configuration loadConfiguration(String name)
Synchronized method to load configurations. Ensures that any configuration is loaded only once.

Parameters:
name - name of the requested configuration
Returns:
Configuration at the given name
Throws:
ConfigurationNotFoundException - indicates there is no configuration at the given name


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.