Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


com.tangosol.net
Class ScopedCacheFactoryBuilder

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

All Implemented Interfaces:
CacheFactoryBuilder
Direct Known Subclasses:
ContainerAdapter.ContainerCacheFactoryBuilder, DefaultCacheFactoryBuilder, SingletonCacheFactoryBuilder

public class ScopedCacheFactoryBuilder
extends java.lang.Object
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_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 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(java.lang.String sConfigURI, java.lang.ClassLoader loader)
          Construct and configure a ConfigurableCacheFactory for the specified cache config URI and ClassLoader.
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).
protected  java.util.Map ensureConfigMap(java.lang.ClassLoader loader)
          Ensure that a map from URL 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  XmlElement getConfigurableCacheFactoryConfig()
          Return the XML configuration used for the construction of a ConfigurableCacheFactory.
protected  ConfigurableCacheFactory getFactory(java.lang.String sConfigURI, java.lang.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  ConfigurableCacheFactory instantiateFactory(java.lang.ClassLoader loader, XmlElement xmlConfig, XmlElement xmlFactory, java.lang.String sConfigURI, java.lang.String sPofConfigURI, ScopeResolver scopeResolver)
          Create a new instance of ConfigurableCacheFactory based on a given ClassLoader and cache configuration XML.
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.
protected  java.lang.String resolveURI(java.lang.String sConfigURI)
          Resolve the URI that identifies the cache configuration.
protected  java.net.URL resolveURL(java.lang.String sConfigURI, java.lang.ClassLoader loader)
          Resolve the URL based on the provided configuration URI.
 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.
 ConfigurableCacheFactory setConfigurableCacheFactory(ConfigurableCacheFactory ccf, java.lang.String sConfigURI, java.lang.ClassLoader loader, boolean fReplace)
          Dynamically set the ConfigurableCacheFactory 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_mapConfigByLoader

protected java.util.Map 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.

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. If a ConfigurableCacheFactory for the given class loader already exists, the factory will be released.
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. If a ConfigurableCacheFactory for the given URI and class loader already exists, the factory will be released.
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

setConfigurableCacheFactory

public ConfigurableCacheFactory setConfigurableCacheFactory(ConfigurableCacheFactory ccf,
                                                            java.lang.String sConfigURI,
                                                            java.lang.ClassLoader loader,
                                                            boolean fReplace)
Dynamically set the 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.
Specified by:
setConfigurableCacheFactory in interface CacheFactoryBuilder
Parameters:
ccf - the ConfigurableCacheFactory instance
sConfigURI - the configuration URI; must not be null
loader - class loader for which the configuration should be used; must not be null
fReplace - 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(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 ConfigurableCacheFactory instance for the specified URI and class loader.
Parameters:
sConfigURI - the configuration URI to return a ConfigurableCacheFactory for
loader - the loader to return a CCF for
Returns:
a ConfigurableCacheFactory 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

ensureConfigMap

protected java.util.Map ensureConfigMap(java.lang.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

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

getConfigurableCacheFactoryConfig

protected XmlElement getConfigurableCacheFactoryConfig()
Return the XML configuration used for the construction of a ConfigurableCacheFactory.
Returns:
the XmlElement that contains construction configuration

buildFactory

protected ConfigurableCacheFactory buildFactory(java.lang.String sConfigURI,
                                                java.lang.ClassLoader loader)
Construct and configure a ConfigurableCacheFactory for the specified cache config URI and ClassLoader.
Parameters:
sConfigURI - the URI to the cache configuration
loader - the ClassLoader associated with the factory
Returns:
a ConfigurableCacheFactory for the specified XML configuration

instantiateFactory

protected ConfigurableCacheFactory instantiateFactory(java.lang.ClassLoader loader,
                                                      XmlElement xmlConfig,
                                                      XmlElement xmlFactory,
                                                      java.lang.String sConfigURI,
                                                      java.lang.String sPofConfigURI,
                                                      ScopeResolver scopeResolver)
Create a new instance of ConfigurableCacheFactory based on a given ClassLoader and cache configuration XML.
Parameters:
loader - the ClassLoader used to instantiate the ConfigurableCacheFactory
xmlConfig - the XmlElement containing the cache configuration
xmlFactory - the XmlElement containing the factory definition
sConfigURI - the URI to the cache configuration
sPofConfigURI - the POF configuration URI
scopeResolver - the ScopeResolver used to scope services
Returns:
the ConfigurableCacheFactory created

resolveURI

protected java.lang.String resolveURI(java.lang.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 via 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.
Parameters:
sConfigURI - the passed in URI
Returns:
the resolved URI
See Also:
URI_DEFAULT

resolveURL

protected java.net.URL resolveURL(java.lang.String sConfigURI,
                                  java.lang.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 of
loader - the ClassLoader to use
Returns:
a URL for the resource

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 12.1.2.0.3

E26043-02


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