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
Implementation of
CacheFactoryBuilder that manages multiple
instances of ConfigurableCacheFactory. 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
FieldsModifier and TypeFieldDescriptionprotected final ScopeResolverScope resolver used to resolve scope name upon CCF construction.protected Map<ClassLoader, Map<String, ConfigurableCacheFactory>> Mapping used to associate class loaders with the cache factories that are configured on them.protected Map<ClassLoader, Map<URI, XmlElement>> Mapping used to associate class loaders with specific configuration elements.Fields inherited from interface com.tangosol.net.CacheFactoryBuilder
URI_DEFAULTFields inherited from interface com.tangosol.net.SessionProvider
PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor; reads scope resolver configuration from operational configuration file (tangosol-coherence.xml).ScopedCacheFactoryBuilder(ScopeResolver resolver) Constructor to provide a custom scope resolver. -
Method Summary
Modifier and TypeMethodDescriptionprotected ConfigurableCacheFactorybuildFactory(String sConfigURI, ClassLoader loader) Construct and configure aConfigurableCacheFactoryfor the specified cache config URI andClassLoader.protected ConfigurableCacheFactorybuildFactory(String sConfigURI, ClassLoader loader, ParameterResolver paramResolver) Construct and configure aConfigurableCacheFactoryfor 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).Return the default ConfigurableCacheFactory for a given class loader.getConfigurableCacheFactory(String sConfigURI, ClassLoader loader) Return the ConfigurableCacheFactory for a given URI and class loader.getConfigurableCacheFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver) Return the ConfigurableCacheFactory for a given URI and class loader.protected XmlElementReturn the XML configuration used for the construction of aConfigurableCacheFactory.protected ConfigurableCacheFactorygetFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver) Helper method to return aConfigurableCacheFactoryinstance for the specified URI and class loader.Obtain the scope resolver for this builder.protected XmlElementgetXmlConfig(ClassLoader loader, URL url) Return theXML configrelating to the provided ClassLoader and URL, or null.protected ConfigurableCacheFactoryinstantiateFactory(ClassLoader loader, XmlElement xmlConfig, XmlElement xmlFactory, String sPofConfigURI, String sScopeName, ParameterResolver resolver) Create a new instance ofConfigurableCacheFactorybased on a givenClassLoaderand cache configuration XML.protected ScopeResolverInstantiate the defaultScopeResolver.protected XmlElementloadConfigFromURI(String sConfigURI, ClassLoader loader) Load the XML configuration from the specified URI.voidrelease(ConfigurableCacheFactory factory) Release the specified ConfigurableCacheFactory.voidreleaseAll(ClassLoader loader) Release all ConfigurableCacheFactory objects for a given ClassLoader.protected StringresolveURI(String sConfigURI) Resolve the URI that identifies the cache configuration.protected URLresolveURL(String sConfigURI, ClassLoader loader) Resolve the URL based on the provided configuration URI.voidsetCacheConfiguration(ClassLoader loader, XmlElement xmlConfig) Dynamically set the default cache configuration for a given class loader.voidsetCacheConfiguration(String sConfigURI, ClassLoader loader, XmlElement xmlConfig) Dynamically set the cache configuration for a given URI and class loader.setConfigurableCacheFactory(ConfigurableCacheFactory ccf, String sConfigURI, ClassLoader loader, boolean fReplace) Dynamically set theConfigurableCacheFactoryfor a given URI and class loader.protected voidsetXmlConfig(ClassLoader loader, URL url, XmlElement xml) Register the providedXML configwith the ClassLoader and URL.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tangosol.net.CacheFactoryBuilder
createSession, releaseSessionMethods inherited from interface com.tangosol.net.SessionProvider
close, compareTo, createSession, createSession, createSession, createSession, getPriority
-
Field Details
-
f_scopeResolver
Scope resolver used to resolve scope name upon CCF construction. -
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
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 Details
-
ScopedCacheFactoryBuilder
public ScopedCacheFactoryBuilder()Default constructor; reads scope resolver configuration from operational configuration file (tangosol-coherence.xml). -
ScopedCacheFactoryBuilder
Constructor to provide a custom scope resolver.- Parameters:
resolver- scope resolver
-
-
Method Details
-
getScopeResolver
Obtain the scope resolver for this builder.- Returns:
- scope resolver
-
getConfigurableCacheFactory
Return the default ConfigurableCacheFactory for a given class loader.- Specified by:
getConfigurableCacheFactoryin 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
Return the ConfigurableCacheFactory for a given URI and class loader.- Specified by:
getConfigurableCacheFactoryin 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:
getConfigurableCacheFactoryin interfaceCacheFactoryBuilder- Parameters:
sConfigURI- the configuration URI; must not be nullloader- class loader for which the configuration should be used; must not be nullresolver- the optionalParameterResolverto use to resolve configuration parameters- Returns:
- the ConfigurableCacheFactory for a given URI and class loader
-
setCacheConfiguration
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:
setCacheConfigurationin interfaceCacheFactoryBuilder- Parameters:
loader- class loader for which the configuration should be used; must not be nullxmlConfig- cache configuration in xml element format
-
setCacheConfiguration
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:
setCacheConfigurationin 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 theConfigurableCacheFactoryfor 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:
setConfigurableCacheFactoryin 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
Release all ConfigurableCacheFactory objects for a given ClassLoader.- Specified by:
releaseAllin interfaceCacheFactoryBuilder- Parameters:
loader- the class loader for which all associated cache factories should be released
-
release
Release the specified ConfigurableCacheFactory.- Specified by:
releasein interfaceCacheFactoryBuilder- Parameters:
factory- the ConfigurableCacheFactory to release
-
instantiateScopeResolver
Instantiate the defaultScopeResolver.If the
scope-resolverelement of thecache-factory-builderelement of the operational configuration has been specified this will be used to determine theScopeResolverimplementation to use otherwise theNullImplementationresolver will be used.- Returns:
- the default
ScopeResolver
-
getFactory
protected ConfigurableCacheFactory getFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver) Helper method to return aConfigurableCacheFactoryinstance for the specified URI and class loader.- Parameters:
sConfigURI- the configuration URI to return aConfigurableCacheFactoryforloader- the loader to return a CCF for- Returns:
- a
ConfigurableCacheFactoryinstance
-
ensureConfigCCFMap
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
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
Return theXML configrelating 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
Register the providedXML configwith 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
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
Return the XML configuration used for the construction of aConfigurableCacheFactory.- Returns:
- the
XmlElementthat contains construction configuration
-
buildFactory
Construct and configure aConfigurableCacheFactoryfor the specified cache config URI andClassLoader.- Parameters:
sConfigURI- the URI to the cache configurationloader- theClassLoaderassociated with the factory- Returns:
- a ConfigurableCacheFactory for the specified XML configuration
-
buildFactory
protected ConfigurableCacheFactory buildFactory(String sConfigURI, ClassLoader loader, ParameterResolver paramResolver) Construct and configure aConfigurableCacheFactoryfor the specified cache config URI andClassLoader.- Parameters:
sConfigURI- the URI to the cache configurationloader- theClassLoaderassociated with the factoryparamResolver- an optionalParameterResolverto 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 ofConfigurableCacheFactorybased on a givenClassLoaderand cache configuration XML.- Parameters:
loader- theClassLoaderused to instantiate theConfigurableCacheFactoryxmlConfig- theXmlElementcontaining the cache configurationxmlFactory- theXmlElementcontaining the factory definitionsPofConfigURI- the POF configuration URIsScopeName- an optional scope name- Returns:
- the
ConfigurableCacheFactorycreated
-
resolveURI
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:
-
resolveURL
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- theClassLoaderto use- Returns:
- a
URLfor the resource
-