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 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 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
  • Field Details

    • 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 Details

    • 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 Details

    • 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 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(String sConfigURI, 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
    • getConfigurableCacheFactory

      public ConfigurableCacheFactory getConfigurableCacheFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver)
      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
      resolver - the optional ParameterResolver 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 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(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 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, String sConfigURI, 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(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
    • instantiateScopeResolver

      protected ScopeResolver instantiateScopeResolver()
      Instantiate the default ScopeResolver.

      If the the scope-resolver element of the cache-factory-builder element of the operational configuration has been specified this will be used to determine the ScopeResolver implementation to use otherwise the NullImplementation resolver will be used.

      Returns:
      the default ScopeResolver
    • getFactory

      protected ConfigurableCacheFactory getFactory(String sConfigURI, ClassLoader loader, ParameterResolver resolver)
      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 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 the XML config relating to the provided ClassLoader and URL, or null.
      Parameters:
      loader - the ClassLoader the XML was registered with
      url - 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 provided XML config with the ClassLoader and URL.
      Parameters:
      loader - the ClassLoader the XML is to be registered with
      url - the URL the XML is to be registered with
      xml - 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 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(String sConfigURI, 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
    • buildFactory

      protected ConfigurableCacheFactory buildFactory(String sConfigURI, ClassLoader loader, ParameterResolver paramResolver)
      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
      paramResolver - an optional ParameterResolver 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 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
      sPofConfigURI - the POF configuration URI
      sScopeName - 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 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:
    • 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 of
      loader - the ClassLoader to use
      Returns:
      a URL for the resource