public class ScopedCacheFactoryBuilder extends Object implements CacheFactoryBuilder
CacheFactoryBuilder that manages multiple instances of ConfigurableCacheFactory. This implementation supports isolation of cache configurations via the following mechanisms:
<scope-name> attribute. If this element exists, this attribute will be set on the CCF instance.instantiateFactory(java.lang.ClassLoader, com.tangosol.run.xml.XmlElement, com.tangosol.run.xml.XmlElement, java.lang.String, java.lang.String, com.tangosol.application.Context) method.The scope name may be used by the ConfigurableCacheFactory instance as a service name prefix.
SessionProvider.Option| Modifier and Type | Field and Description |
|---|---|
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.
|
protected ScopeResolver |
m_scopeResolver
Scope resolver used to resolve scope name upon CCF construction.
|
protected static String |
URI_DEFAULT
Internally used "default" URI identifier.
|
| Constructor and 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.
|
| Modifier and Type | Method and Description |
|---|---|
protected ConfigurableCacheFactory |
buildFactory(String sConfigURI, ClassLoader loader)
Construct and configure a
ConfigurableCacheFactory for the specified cache config URI and ClassLoader. |
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.
|
protected XmlElement |
getConfigurableCacheFactoryConfig()
Return the XML configuration used for the construction of a
ConfigurableCacheFactory. |
protected ConfigurableCacheFactory |
getFactory(String sConfigURI, ClassLoader loader)
Helper method to return a
ConfigurableCacheFactory 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 the
XML config relating to the provided ClassLoader and URL, or null. |
protected ConfigurableCacheFactory |
instantiateFactory(ClassLoader loader, XmlElement xmlConfig, XmlElement xmlFactory, String sPofConfigURI, String sScopeName, Context ctx)
Create a new instance of
ConfigurableCacheFactory based on a given ClassLoader and cache configuration XML. |
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 the
ConfigurableCacheFactory for a given URI and class loader. |
protected void |
setXmlConfig(ClassLoader loader, URL url, XmlElement xml)
Register the provided
XML config with the ClassLoader and URL. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateSessiongetprotected ScopeResolver m_scopeResolver
protected Map<ClassLoader,Map<String,ConfigurableCacheFactory>> m_mapByLoader
protected Map<ClassLoader,Map<URI,XmlElement>> m_mapConfigByLoader
protected static final String URI_DEFAULT
public ScopedCacheFactoryBuilder()
public ScopedCacheFactoryBuilder(ScopeResolver resolver)
resolver - scope resolverpublic ScopeResolver getScopeResolver()
public ConfigurableCacheFactory getConfigurableCacheFactory(ClassLoader loader)
getConfigurableCacheFactory in interface CacheFactoryBuilderloader - class loader for which the configuration should be used; must not be nullpublic ConfigurableCacheFactory getConfigurableCacheFactory(String sConfigURI, ClassLoader loader)
getConfigurableCacheFactory in interface CacheFactoryBuildersConfigURI - the configuration URI; must not be nullloader - class loader for which the configuration should be used; must not be nullpublic void setCacheConfiguration(ClassLoader loader, XmlElement xmlConfig)
setCacheConfiguration in interface CacheFactoryBuilderloader - class loader for which the configuration should be used; must not be nullxmlConfig - cache configuration in xml element formatpublic void setCacheConfiguration(String sConfigURI, ClassLoader loader, XmlElement xmlConfig)
setCacheConfiguration in interface CacheFactoryBuildersConfigURI - 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 formatpublic ConfigurableCacheFactory setConfigurableCacheFactory(ConfigurableCacheFactory ccf, String sConfigURI, ClassLoader loader, boolean fReplace)
ConfigurableCacheFactory 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.setConfigurableCacheFactory in interface CacheFactoryBuilderccf - 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 registeredpublic void releaseAll(ClassLoader loader)
releaseAll in interface CacheFactoryBuilderloader - the class loader for which all associated cache factories should be releasedpublic void release(ConfigurableCacheFactory factory)
release in interface CacheFactoryBuilderfactory - the ConfigurableCacheFactory to releaseprotected ConfigurableCacheFactory getFactory(String sConfigURI, ClassLoader loader)
ConfigurableCacheFactory instance for the specified URI and class loader.sConfigURI - the configuration URI to return a ConfigurableCacheFactory forloader - the loader to return a CCF forConfigurableCacheFactory instanceprotected Map<String,ConfigurableCacheFactory> ensureConfigCCFMap(ClassLoader loader)
loader - the class loader to which the map correspondsprotected Map<URI,XmlElement> ensureConfigMap(ClassLoader loader)
loader - the class loader to which the map correspondsprotected XmlElement getXmlConfig(ClassLoader loader, URL url)
XML config relating to the provided ClassLoader and URL, or null.loader - the ClassLoader the XML was registered withurl - the URL the XML was registered withprotected void setXmlConfig(ClassLoader loader, URL url, XmlElement xml)
XML config with the ClassLoader and URL.loader - the ClassLoader the XML is to be registered withurl - the URL the XML is to be registered withxml - the XML config to registerprotected XmlElement loadConfigFromURI(String sConfigURI, ClassLoader loader)
sConfigURI - the configuration URI; must not be nullloader - class loader to useprotected XmlElement getConfigurableCacheFactoryConfig()
ConfigurableCacheFactory.XmlElement that contains construction configurationprotected ConfigurableCacheFactory buildFactory(String sConfigURI, ClassLoader loader)
ConfigurableCacheFactory for the specified cache config URI and ClassLoader.sConfigURI - the URI to the cache configurationloader - the ClassLoader associated with the factoryprotected ConfigurableCacheFactory instantiateFactory(ClassLoader loader, XmlElement xmlConfig, XmlElement xmlFactory, String sPofConfigURI, String sScopeName, Context ctx)
ConfigurableCacheFactory based on a given ClassLoader and cache configuration XML.loader - the ClassLoader used to instantiate the ConfigurableCacheFactoryxmlConfig - the XmlElement containing the cache configurationxmlFactory - the XmlElement containing the factory definitionsPofConfigURI - the POF configuration URIsScopeName - an optional scope namectx - an optional ContainerContext referenceConfigurableCacheFactory createdprotected String resolveURI(String sConfigURI)
CacheFactory.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.sConfigURI - the passed in URIURI_DEFAULTprotected URL resolveURL(String sConfigURI, ClassLoader loader)
sConfigURI - the configuration URI to make a URL out ofloader - the ClassLoader to useURL for the resource