Package com.tangosol.net
Class ScopedCacheFactoryBuilder
- java.lang.Object
-
- com.tangosol.net.ScopedCacheFactoryBuilder
-
- All Implemented Interfaces:
CacheFactoryBuilder
,SessionProvider
,Comparable<SessionProvider>
- Direct Known Subclasses:
DefaultCacheFactoryBuilder
,SingletonCacheFactoryBuilder
public class ScopedCacheFactoryBuilder extends Object implements CacheFactoryBuilder
Implementation ofCacheFactoryBuilder
that manages multiple instances ofConfigurableCacheFactory
. This implementation supports isolation of cache configurations via the following mechanisms:- It parses the cache configuration file for the
<scope-name>
attribute. If this element exists, this attribute will be set on the CCF instance. - The scope name can be explicitly passed to the
instantiateFactory(java.lang.ClassLoader, com.tangosol.run.xml.XmlElement, com.tangosol.run.xml.XmlElement, java.lang.String, java.lang.String, com.tangosol.config.expression.ParameterResolver)
method.
The scope name may be used by the
ConfigurableCacheFactory
instance as a service name prefix.- Since:
- Coherence 3.7
- Author:
- pp 2010.01.20
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.tangosol.net.SessionProvider
SessionProvider.Context, SessionProvider.DefaultContext, SessionProvider.Option, SessionProvider.Provider, SessionProvider.Providers
-
-
Field Summary
Fields Modifier and Type Field Description protected ScopeResolver
f_scopeResolver
Scope resolver used to resolve scope name upon CCF construction.protected Map<ClassLoader,Map<String,ConfigurableCacheFactory>>
m_mapByLoader
Mapping used to associate class loaders with the cache factories that are configured on them.protected Map<ClassLoader,Map<URI,XmlElement>>
m_mapConfigByLoader
Mapping used to associate class loaders with specific configuration elements.-
Fields inherited from interface com.tangosol.net.CacheFactoryBuilder
URI_DEFAULT
-
Fields inherited from interface com.tangosol.net.SessionProvider
PRIORITY
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ConfigurableCacheFactory
buildFactory(String sConfigURI, ClassLoader loader)
Construct and configure aConfigurableCacheFactory
for the specified cache config URI andClassLoader
.protected ConfigurableCacheFactory
buildFactory(String sConfigURI, ClassLoader loader, ParameterResolver paramResolver)
Construct and configure aConfigurableCacheFactory
for the specified cache config URI andClassLoader
.protected Map<String,ConfigurableCacheFactory>
ensureConfigCCFMap(ClassLoader loader)
Ensure that a map from URI to ConfigurableCacheFactory for the specified loader exists (creating it if necessary).protected Map<URI,XmlElement>
ensureConfigMap(ClassLoader loader)
Ensure that a map from URL to ConfigurableCacheFactory for the specified loader exists (creating it if necessary).ConfigurableCacheFactory
getConfigurableCacheFactory(ClassLoader loader)
Return the default ConfigurableCacheFactory for a given class loader.ConfigurableCacheFactory
getConfigurableCacheFactory(String sConfigURI, ClassLoader loader)
Return the ConfigurableCacheFactory for a given URI and class loader.ConfigurableCacheFactory
getConfigurableCacheFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver)
Return the ConfigurableCacheFactory for a given URI and class loader.protected XmlElement
getConfigurableCacheFactoryConfig()
Return the XML configuration used for the construction of aConfigurableCacheFactory
.protected ConfigurableCacheFactory
getFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver)
Helper method to return aConfigurableCacheFactory
instance for the specified URI and class loader.ScopeResolver
getScopeResolver()
Obtain the scope resolver for this builder.protected XmlElement
getXmlConfig(ClassLoader loader, URL url)
Return theXML config
relating to the provided ClassLoader and URL, or null.protected ConfigurableCacheFactory
instantiateFactory(ClassLoader loader, XmlElement xmlConfig, XmlElement xmlFactory, String sPofConfigURI, String sScopeName, ParameterResolver resolver)
Create a new instance ofConfigurableCacheFactory
based on a givenClassLoader
and cache configuration XML.protected ScopeResolver
instantiateScopeResolver()
Instantiate the defaultScopeResolver
.protected XmlElement
loadConfigFromURI(String sConfigURI, ClassLoader loader)
Load the XML configuration from the specified URI.void
release(ConfigurableCacheFactory factory)
Release the specified ConfigurableCacheFactory.void
releaseAll(ClassLoader loader)
Release all ConfigurableCacheFactory objects for a given ClassLoader.protected String
resolveURI(String sConfigURI)
Resolve the URI that identifies the cache configuration.protected URL
resolveURL(String sConfigURI, ClassLoader loader)
Resolve the URL based on the provided configuration URI.void
setCacheConfiguration(ClassLoader loader, XmlElement xmlConfig)
Dynamically set the default cache configuration for a given class loader.void
setCacheConfiguration(String sConfigURI, ClassLoader loader, XmlElement xmlConfig)
Dynamically set the cache configuration for a given URI and class loader.ConfigurableCacheFactory
setConfigurableCacheFactory(ConfigurableCacheFactory ccf, String sConfigURI, ClassLoader loader, boolean fReplace)
Dynamically set theConfigurableCacheFactory
for a given URI and class loader.protected void
setXmlConfig(ClassLoader loader, URL url, XmlElement xml)
Register the providedXML config
with the ClassLoader and URL.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.tangosol.net.CacheFactoryBuilder
createSession, releaseSession
-
Methods inherited from interface com.tangosol.net.SessionProvider
close, compareTo, createSession, createSession, createSession, createSession, getPriority
-
-
-
-
Field Detail
-
f_scopeResolver
protected final ScopeResolver f_scopeResolver
Scope resolver used to resolve scope name upon CCF construction.
-
m_mapByLoader
protected Map<ClassLoader,Map<String,ConfigurableCacheFactory>> 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_mapConfigByLoader
protected Map<ClassLoader,Map<URI,XmlElement>> m_mapConfigByLoader
Mapping used to associate class loaders with specific configuration elements. The map is (weakly) keyed by class loader instances and holds a map of URL to XmlElement as 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
-
getConfigurableCacheFactory
public ConfigurableCacheFactory getConfigurableCacheFactory(ClassLoader loader)
Return the default ConfigurableCacheFactory for a given class loader.- Specified by:
getConfigurableCacheFactory
in interfaceCacheFactoryBuilder
- 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(String sConfigURI, ClassLoader loader)
Return the ConfigurableCacheFactory for a given URI and class loader.- Specified by:
getConfigurableCacheFactory
in interfaceCacheFactoryBuilder
- Parameters:
sConfigURI
- the configuration URI; must not be nullloader
- class loader for which the configuration should be used; must not be null- Returns:
- the ConfigurableCacheFactory for a given URI and class loader
-
getConfigurableCacheFactory
public ConfigurableCacheFactory getConfigurableCacheFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver)
Return the ConfigurableCacheFactory for a given URI and class loader.- Specified by:
getConfigurableCacheFactory
in interfaceCacheFactoryBuilder
- Parameters:
sConfigURI
- the configuration URI; must not be nullloader
- class loader for which the configuration should be used; must not be nullresolver
- the optionalParameterResolver
to use to resolve configuration parameters- Returns:
- the ConfigurableCacheFactory for a given URI and class loader
-
setCacheConfiguration
public void setCacheConfiguration(ClassLoader loader, XmlElement xmlConfig)
Dynamically set the default cache configuration for a given class loader. If a ConfigurableCacheFactory for the given class loader already exists, the factory will be released.- Specified by:
setCacheConfiguration
in interfaceCacheFactoryBuilder
- Parameters:
loader
- class loader for which the configuration should be used; must not be nullxmlConfig
- cache configuration in xml element format
-
setCacheConfiguration
public void setCacheConfiguration(String sConfigURI, ClassLoader loader, XmlElement xmlConfig)
Dynamically set the cache configuration for a given URI and class loader. If a ConfigurableCacheFactory for the given URI and class loader already exists, the factory will be released.- Specified by:
setCacheConfiguration
in interfaceCacheFactoryBuilder
- Parameters:
sConfigURI
- the configuration URI; must not be nullloader
- class loader for which the configuration should be used; must not be nullxmlConfig
- cache configuration in xml element format
-
setConfigurableCacheFactory
public ConfigurableCacheFactory setConfigurableCacheFactory(ConfigurableCacheFactory ccf, String sConfigURI, ClassLoader loader, boolean fReplace)
Dynamically set theConfigurableCacheFactory
for a given URI and class loader. If a ConfigurableCacheFactory for the given URI and class loader already exists and the replacement is requested, the factory will be released.- Specified by:
setConfigurableCacheFactory
in interfaceCacheFactoryBuilder
- Parameters:
ccf
- the ConfigurableCacheFactory instancesConfigURI
- the configuration URI; must not be nullloader
- class loader for which the configuration should be used; must not be nullfReplace
- specifies whether to replace a ConfigurableCacheFactory if one is already registered- Returns:
- the previous ConfigurableCacheFactory associated with the URI and loader, if any
-
releaseAll
public void releaseAll(ClassLoader loader)
Release all ConfigurableCacheFactory objects for a given ClassLoader.- Specified by:
releaseAll
in interfaceCacheFactoryBuilder
- 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 interfaceCacheFactoryBuilder
- Parameters:
factory
- the ConfigurableCacheFactory to release
-
instantiateScopeResolver
protected ScopeResolver instantiateScopeResolver()
Instantiate the defaultScopeResolver
.If the the
scope-resolver
element of thecache-factory-builder
element of the operational configuration has been specified this will be used to determine theScopeResolver
implementation to use otherwise theNullImplementation
resolver will be used.- Returns:
- the default
ScopeResolver
-
getFactory
protected ConfigurableCacheFactory getFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver)
Helper method to return aConfigurableCacheFactory
instance for the specified URI and class loader.- Parameters:
sConfigURI
- the configuration URI to return aConfigurableCacheFactory
forloader
- the loader to return a CCF for- Returns:
- a
ConfigurableCacheFactory
instance
-
ensureConfigCCFMap
protected Map<String,ConfigurableCacheFactory> ensureConfigCCFMap(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
-
ensureConfigMap
protected Map<URI,XmlElement> ensureConfigMap(ClassLoader loader)
Ensure that a map from URL 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 URL to ConfigurableCacheFactory
-
getXmlConfig
protected XmlElement getXmlConfig(ClassLoader loader, URL url)
Return theXML config
relating to the provided ClassLoader and URL, or null.- Parameters:
loader
- the ClassLoader the XML was registered withurl
- the URL the XML was registered with- Returns:
- the XML config relating to the provided ClassLoader and URL, or null
-
setXmlConfig
protected void setXmlConfig(ClassLoader loader, URL url, XmlElement xml)
Register the providedXML config
with the ClassLoader and URL.- Parameters:
loader
- the ClassLoader the XML is to be registered withurl
- the URL the XML is to be registered withxml
- the XML config to register
-
loadConfigFromURI
protected XmlElement loadConfigFromURI(String sConfigURI, ClassLoader loader)
Load the XML configuration from the specified URI.- Parameters:
sConfigURI
- the configuration URI; must not be nullloader
- class loader to use- Returns:
- the XML configuration, or null if the config could not be loaded
-
getConfigurableCacheFactoryConfig
protected XmlElement getConfigurableCacheFactoryConfig()
Return the XML configuration used for the construction of aConfigurableCacheFactory
.- Returns:
- the
XmlElement
that contains construction configuration
-
buildFactory
protected ConfigurableCacheFactory buildFactory(String sConfigURI, ClassLoader loader)
Construct and configure aConfigurableCacheFactory
for the specified cache config URI andClassLoader
.- Parameters:
sConfigURI
- the URI to the cache configurationloader
- theClassLoader
associated with the factory- Returns:
- a ConfigurableCacheFactory for the specified XML configuration
-
buildFactory
protected ConfigurableCacheFactory buildFactory(String sConfigURI, ClassLoader loader, ParameterResolver paramResolver)
Construct and configure aConfigurableCacheFactory
for the specified cache config URI andClassLoader
.- Parameters:
sConfigURI
- the URI to the cache configurationloader
- theClassLoader
associated with the factoryparamResolver
- an optionalParameterResolver
to use to resolve configuration parameters- Returns:
- a ConfigurableCacheFactory for the specified XML configuration
-
instantiateFactory
protected ConfigurableCacheFactory instantiateFactory(ClassLoader loader, XmlElement xmlConfig, XmlElement xmlFactory, String sPofConfigURI, String sScopeName, ParameterResolver resolver)
Create a new instance ofConfigurableCacheFactory
based on a givenClassLoader
and cache configuration XML.- Parameters:
loader
- theClassLoader
used to instantiate theConfigurableCacheFactory
xmlConfig
- theXmlElement
containing the cache configurationxmlFactory
- theXmlElement
containing the factory definitionsPofConfigURI
- the POF configuration URIsScopeName
- an optional scope name- Returns:
- the
ConfigurableCacheFactory
created
-
resolveURI
protected String resolveURI(String sConfigURI)
Resolve the URI that identifies the cache configuration. The URI provided may be a normal URL or Resource, or it may be a "special" default URI that is used when a specific cache configuration file is not indicated (for example, if the user requests a factory viaCacheFactory.getConfigurableCacheFactory()
. If the "default" URI is requested, the URI is resolved to the default cache configuration name indicated in the operational configuration file; otherwise the provided URI is returned.- Parameters:
sConfigURI
- the passed in URI- Returns:
- the resolved URI
- See Also:
CacheFactoryBuilder.URI_DEFAULT
-
resolveURL
protected URL resolveURL(String sConfigURI, ClassLoader loader)
Resolve the URL based on the provided configuration URI. The resolution consists of locating the URI as a resource or a file and the creation of a corresponding URL. If the URI cannot be located, a "placeholder" file URL will be created.- Parameters:
sConfigURI
- the configuration URI to make a URL out ofloader
- theClassLoader
to use- Returns:
- a
URL
for the resource
-
-