Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


com.tangosol.net
Class ScopedCacheFactoryBuilder

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.net.ScopedCacheFactoryBuilder

All Implemented Interfaces:
CacheFactoryBuilder
Direct Known Subclasses:
DefaultCacheFactoryBuilder

public class ScopedCacheFactoryBuilder
extends Base
implements CacheFactoryBuilder

Implementation of CacheFactoryBuilder that manages multiple instances of ConfigurableCacheFactory. This implementation supports isolation of cache configurations via the following mechanisms:

  1. It parses the cache configuration file for the <scope-name> attribute. If this element exists, this attribute will be set on the CCF instance.
  2. The scope name provided by the cache configuration can be modified (or substituted) by providing this builder with an instance of ScopeResolver. This will usually be done by containers that manage multiple applications that each use their own cache configuration.

This scope name may be used by the ConfigurableCacheFactory instance as a service name prefix.

Since:
Coherence 3.7
Author:
pp 2010.01.20

Field Summary
protected  java.util.Map m_mapByLoader
          Mapping used to associate class loaders with the cache factories that are configured on them.
protected  java.util.Map m_mapInternedConfig
          Mapping of configuration resource URLs to the xml configuration elements loaded from those resources.
protected  ScopeResolver m_scopeResolver
          Scope resolver used to resolve scope name upon CCF construction
protected static java.lang.String URI_DEFAULT
          Internally used "default" URI identifier.

 

Constructor Summary
ScopedCacheFactoryBuilder()
          Default constructor; reads scope resolver configuration from operational configuration file (tangosol-coherence.xml)
ScopedCacheFactoryBuilder(ScopeResolver resolver)
          Constructor to provide a custom scope resolver

 

Method Summary
protected  ConfigurableCacheFactory buildFactory(XmlElement xmlConfig, java.lang.ClassLoader loader)
          Construct a ConfigurableCacheFactory for the specified XML configuration.
protected  void configureScope(java.lang.String sConfigURI, java.lang.ClassLoader loader, XmlElement xmlConfig, ConfigurableCacheFactory ccf)
          For a given cache configuration URI and ClassLoader, configure the scope name for the associated ConfigurableCacheFactory.
protected  java.util.Map ensureConfigCCFMap(java.lang.ClassLoader loader)
          Ensure that a map from URI to ConfigurableCacheFactory for the specified loader exists (creating it if necessary).
 ConfigurableCacheFactory getConfigurableCacheFactory(java.lang.ClassLoader loader)
          Return the default ConfigurableCacheFactory for a given class loader.
 ConfigurableCacheFactory getConfigurableCacheFactory(java.lang.String sConfigURI, java.lang.ClassLoader loader)
          Return the ConfigurableCacheFactory for a given URI and class loader.
protected  ConfigurableCacheFactory getDefaultFactory(java.lang.ClassLoader loader)
          Return a default cache factory for the specified loader.
protected  ConfigurableCacheFactory getFactory(java.lang.String sConfigURI, java.lang.ClassLoader loader)
          Helper method to return a CCF instance for the specified URI and class loader.
 ScopeResolver getScopeResolver()
          Obtain the scope resolver for this builder
protected  XmlElement loadConfigFromURI(java.lang.String sConfigURI, java.lang.ClassLoader loader)
          Load the XML configuration from the specified URI.
 void release(ConfigurableCacheFactory factory)
          Release the specified ConfigurableCacheFactory.
 void releaseAll(java.lang.ClassLoader loader)
          Release all ConfigurableCacheFactory objects for a given ClassLoader.
 void setCacheConfiguration(java.lang.ClassLoader loader, XmlElement xmlConfig)
          Dynamically set the default cache configuration for a given class loader.
 void setCacheConfiguration(java.lang.String sConfigURI, java.lang.ClassLoader loader, XmlElement xmlConfig)
          Dynamically set the cache configuration for a given URI and class loader.
 void setScopeResolver(ScopeResolver scopeResolver)
          Specify the scope resolver for this builder

 

Field Detail

m_scopeResolver

protected ScopeResolver m_scopeResolver
Scope resolver used to resolve scope name upon CCF construction

m_mapByLoader

protected java.util.Map m_mapByLoader
Mapping used to associate class loaders with the cache factories that are configured on them. The map is (weakly) keyed by class loader instances and holds a maps of URI to ConfigurableCacheFactory as a values (e.g. Map<ClassLoader, Map<URI, ConfigurableCacheFactory>>).

m_mapInternedConfig

protected java.util.Map m_mapInternedConfig
Mapping of configuration resource URLs to the xml configuration elements loaded from those resources.

Note: only xml configuration elements that are configured from a loaded resource are interned; externally configured cache factories are excluded.


URI_DEFAULT

protected static final java.lang.String URI_DEFAULT
Internally used "default" URI identifier.
See Also:
Constant Field Values

Constructor Detail

ScopedCacheFactoryBuilder

public ScopedCacheFactoryBuilder()
Default constructor; reads scope resolver configuration from operational configuration file (tangosol-coherence.xml)

ScopedCacheFactoryBuilder

public ScopedCacheFactoryBuilder(ScopeResolver resolver)
Constructor to provide a custom scope resolver
Parameters:
resolver - scope resolver

Method Detail

getScopeResolver

public ScopeResolver getScopeResolver()
Obtain the scope resolver for this builder
Returns:
scope resolver

setScopeResolver

public void setScopeResolver(ScopeResolver scopeResolver)
Specify the scope resolver for this builder
Parameters:
scopeResolver - scope resolver

getConfigurableCacheFactory

public ConfigurableCacheFactory getConfigurableCacheFactory(java.lang.ClassLoader loader)
Return the default ConfigurableCacheFactory for a given class loader.
Specified by:
getConfigurableCacheFactory in interface CacheFactoryBuilder
Parameters:
loader - class loader for which the configuration should be used; must not be null
Returns:
the default ConfigurableCacheFactory for a given class loader

getConfigurableCacheFactory

public ConfigurableCacheFactory getConfigurableCacheFactory(java.lang.String sConfigURI,
                                                            java.lang.ClassLoader loader)
Return the ConfigurableCacheFactory for a given URI and class loader.
Specified by:
getConfigurableCacheFactory in interface CacheFactoryBuilder
Parameters:
sConfigURI - the configuration URI; must not be null
loader - class loader for which the configuration should be used; must not be null
Returns:
the ConfigurableCacheFactory for a given URI and class loader

setCacheConfiguration

public void setCacheConfiguration(java.lang.ClassLoader loader,
                                  XmlElement xmlConfig)
Dynamically set the default cache configuration for a given class loader.
Specified by:
setCacheConfiguration in interface CacheFactoryBuilder
Parameters:
loader - class loader for which the configuration should be used; must not be null
xmlConfig - cache configuration in xml element format

setCacheConfiguration

public void setCacheConfiguration(java.lang.String sConfigURI,
                                  java.lang.ClassLoader loader,
                                  XmlElement xmlConfig)
Dynamically set the cache configuration for a given URI and class loader.
Specified by:
setCacheConfiguration in interface CacheFactoryBuilder
Parameters:
sConfigURI - the configuration URI; must not be null
loader - class loader for which the configuration should be used; must not be null
xmlConfig - cache configuration in xml element format

releaseAll

public void releaseAll(java.lang.ClassLoader loader)
Release all ConfigurableCacheFactory objects for a given ClassLoader.
Specified by:
releaseAll in interface CacheFactoryBuilder
Parameters:
loader - the class loader for which all associated cache factories should be released

release

public void release(ConfigurableCacheFactory factory)
Release the specified ConfigurableCacheFactory.
Specified by:
release in interface CacheFactoryBuilder
Parameters:
factory - the ConfigurableCacheFactory to release

getFactory

protected ConfigurableCacheFactory getFactory(java.lang.String sConfigURI,
                                              java.lang.ClassLoader loader)
Helper method to return a CCF instance for the specified URI and class loader.
Parameters:
sConfigURI - the configuration URI to return a CCF for
loader - the loader to return a CCF for
Returns:
a CCF instance

ensureConfigCCFMap

protected java.util.Map ensureConfigCCFMap(java.lang.ClassLoader loader)
Ensure that a map from URI to ConfigurableCacheFactory for the specified loader exists (creating it if necessary).
Parameters:
loader - the class loader to which the map corresponds
Returns:
a map from URI to ConfigurableCacheFactory

getDefaultFactory

protected ConfigurableCacheFactory getDefaultFactory(java.lang.ClassLoader loader)
Return a default cache factory for the specified loader. The default cache factory is specified by the "configurable-cache-factory-config" XML configuration element.
Parameters:
loader - the loader for which to create a default cache factory
Returns:
a default cache factory

loadConfigFromURI

protected XmlElement loadConfigFromURI(java.lang.String sConfigURI,
                                       java.lang.ClassLoader loader)
Load the XML configuration from the specified URI.
Parameters:
sConfigURI - the configuration URI; must not be null
loader - class loader to use
Returns:
the XML configuration, or null if the config could not be loaded

buildFactory

protected ConfigurableCacheFactory buildFactory(XmlElement xmlConfig,
                                                java.lang.ClassLoader loader)
Construct a ConfigurableCacheFactory for the specified XML configuration.
Parameters:
xmlConfig - the XML configuration to create a factory for
loader - the class loader associated with the factory
Returns:
a ConfigurableCacheFactory for the specified XML configuration

configureScope

protected void configureScope(java.lang.String sConfigURI,
                              java.lang.ClassLoader loader,
                              XmlElement xmlConfig,
                              ConfigurableCacheFactory ccf)
For a given cache configuration URI and ClassLoader, configure the scope name for the associated ConfigurableCacheFactory.
Parameters:
sConfigURI - the configuration URI for the CCF
loader - the ClassLoader for the CCF
xmlConfig - XML configuration for the provided CCF; this may contain a scope name
ccf - the ConfigurableCacheFactory that will have its scope modified

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.