Class ExtensibleConfigurableCacheFactory

  • All Implemented Interfaces:
    ConfigurableCacheFactory

    public class ExtensibleConfigurableCacheFactory
    extends Base
    implements ConfigurableCacheFactory
    ExtensibleConfigurableCacheFactory provides a facility to access caches declared in a "coherence-cache-config.xsd" compliant configuration file.

    It is strongly recommended that developers get a ConfigurableCacheFactory instance via CacheFactory.getCacheFactoryBuilder().getConfigurableCacheFactory(), rather than instantiate an ExtensibleConfigurableCacheFactory instance directly.

    There are various ways of using this factory:

       ExtensibleConfigurableCacheFactory.Dependencies deps =
           ExtensibleConfigurableCacheFactory.DependenciesHelper.newInstance("my-cache-config.xml");
       ExtensibleConfigurableCacheFactory factory =
           new ExtensibleConfigurableCacheFactory(deps);
       ...
       ClassLoader loader  = getClass().getClassLoader();
       NamedCache cacheOne = factory.ensureCache("one", loader);
       NamedCache cacheTwo = factory.ensureCache("two", loader);
     
    Another option is using the static version of the "ensureCache" call:
       ClassLoader loader  = getClass().getClassLoader();
       NamedCache cacheOne = CacheFactory.getCache("one", loader);
     
    which uses an instance of ConfigurableCacheFactory obtained by CacheFactory.getConfigurableCacheFactory().

    Since:
    Coherence 12.1.2
    Author:
    gg 2003.05.26, pfm 2012.12.19
    See Also:
    CacheFactory.getCache(String, ClassLoader, NamedCache.Option...)
    • Field Detail

      • CACHE_NAME

        public static final String CACHE_NAME
        The name of the replaceable parameter representing the cache name.
        See Also:
        Constant Field Values
      • CLASS_LOADER

        public static final String CLASS_LOADER
        The name of the replaceable parameter representing the class loader.
        See Also:
        Constant Field Values
      • MGR_CONTEXT

        public static final String MGR_CONTEXT
        The name of the replaceable parameter representing the backing map manager context.
        See Also:
        Constant Field Values
      • SCHEME_REF

        public static final String SCHEME_REF
        The name of the replaceable parameter representing a scheme reference.
        See Also:
        Constant Field Values
      • CACHE_REF

        public static final String CACHE_REF
        The name of the replaceable parameter representing a cache reference.
        See Also:
        Constant Field Values
      • CACHE_FACTORY

        public static final String CACHE_FACTORY
        The name of the replaceable parameter representing a cache factory.
        See Also:
        Constant Field Values
      • SCHEME_UNKNOWN

        public static final int SCHEME_UNKNOWN
        The unknown scheme type.
        See Also:
        Constant Field Values
      • SCHEME_REPLICATED

        public static final int SCHEME_REPLICATED
        The replicated cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_OPTIMISTIC

        public static final int SCHEME_OPTIMISTIC
        The optimistic cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_DISTRIBUTED

        public static final int SCHEME_DISTRIBUTED
        The distributed cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_NEAR

        public static final int SCHEME_NEAR
        The near cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_VERSIONED_NEAR

        public static final int SCHEME_VERSIONED_NEAR
        The versioned near cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_LOCAL

        public static final int SCHEME_LOCAL
        The local cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_OVERFLOW

        public static final int SCHEME_OVERFLOW
        The overflow map scheme.
        See Also:
        Constant Field Values
      • SCHEME_EXTERNAL

        public static final int SCHEME_EXTERNAL
        The external scheme.
        See Also:
        Constant Field Values
      • SCHEME_EXTERNAL_PAGED

        public static final int SCHEME_EXTERNAL_PAGED
        The paged-external scheme.
        See Also:
        Constant Field Values
      • SCHEME_CLASS

        public static final int SCHEME_CLASS
        The custom class scheme.
        See Also:
        Constant Field Values
      • SCHEME_READ_WRITE_BACKING

        public static final int SCHEME_READ_WRITE_BACKING
        The read write backing map scheme.
        See Also:
        Constant Field Values
      • SCHEME_VERSIONED_BACKING

        public static final int SCHEME_VERSIONED_BACKING
        The versioned backing map scheme.
        See Also:
        Constant Field Values
      • SCHEME_INVOCATION

        public static final int SCHEME_INVOCATION
        The invocation service scheme.
        See Also:
        Constant Field Values
      • SCHEME_PROXY

        public static final int SCHEME_PROXY
        The proxy service scheme.
        See Also:
        Constant Field Values
      • SCHEME_REMOTE_CACHE

        public static final int SCHEME_REMOTE_CACHE
        The remote cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_REMOTE_INVOCATION

        public static final int SCHEME_REMOTE_INVOCATION
        The remote invocation scheme.
        See Also:
        Constant Field Values
      • SCHEME_TRANSACTIONAL

        public static final int SCHEME_TRANSACTIONAL
        The transactional cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_FLASHJOURNAL

        public static final int SCHEME_FLASHJOURNAL
        The flash journal cache scheme.
        See Also:
        Constant Field Values
      • SCHEME_RAMJOURNAL

        public static final int SCHEME_RAMJOURNAL
        The ram journal cache scheme.
        See Also:
        Constant Field Values
      • MAP_SCHEMETYPE_BY_SCHEMENAME

        public static final HashMap<String,​Integer> MAP_SCHEMETYPE_BY_SCHEMENAME
        The mappings from scheme name to scheme type.
      • f_store

        protected final com.tangosol.net.internal.ScopedCacheReferenceStore f_store
        Store that holds cache references scoped by class loader and optionally, if configured, Subject.
      • f_storeTopics

        protected final com.tangosol.net.internal.ScopedReferenceStore<NamedTopic> f_storeTopics
        Store that holds NamedTopic references scoped by class loader and optionally, if configured, Subject.
      • f_dispatcher

        protected final com.tangosol.net.events.internal.ConfigurableCacheFactoryDispatcher f_dispatcher
        ConfigurableCacheFactoryDispatcher linked to this cache factory.
      • m_mapServices

        protected Map<Service,​String> m_mapServices
        Map used to hold references to services that are ensured by this factory where values are non-scoped service names.
      • m_setManager

        protected Set<BackingMapManager> m_setManager
        A Set of BackingMapManager instances registered by this factory.

        Note: we rely on the BackingMapManager classes *not* to override the hashCode() and equals() methods.

      • m_fActivated

        protected boolean m_fActivated
        Indicates whether this factory has been activated.
      • m_fDisposed

        protected boolean m_fDisposed
        Indicates whether this factory has been disposed.
    • Method Detail

      • releaseCache

        public void releaseCache​(NamedCache cache)
        Release a cache and its associated resources.

        Releasing a cache makes it no longer usable, but does not affect the cache itself. In other words, all other references to the cache will still be valid, and the cache data is not affected by releasing the reference. Any attempt to use the released cache reference afterword will result in an exception.

        Specified by:
        releaseCache in interface ConfigurableCacheFactory
        Parameters:
        cache - the cache to release
      • destroyCache

        public void destroyCache​(NamedCache cache)
        Release and destroy this instance of NamedCache.

        Warning: This method is used to completely destroy the specified cache across the cluster. All references in the entire cluster to this cache will be invalidated, the cached data will be cleared, and all internal and associated resources will be released.

        Specified by:
        destroyCache in interface ConfigurableCacheFactory
        Parameters:
        cache - the cache to release
      • activate

        public void activate()
        Activate prepares the factory to be used within a container and should be called before any other factory method.
        Specified by:
        activate in interface ConfigurableCacheFactory
      • getScopeName

        public String getScopeName()
        Return the scope name for this ConfigurableCacheFactory. If specified, this name will be used as a prefix for the name of all services created by this factory.
        Specified by:
        getScopeName in interface ConfigurableCacheFactory
        Returns:
        the scope name for this ConfigurableCacheFactory; may be null
      • getApplicationContext

        public Context getApplicationContext()
        Return the application Context associated with this ECCF.
        Returns:
        the application Context or null, if none is associated
      • getContainerContext

        public ContainerContext getContainerContext()
        Return the ContainerContext associated with this ECCF.
        Returns:
        the ContainerContext or null, if none is associated
      • getRequestTimeout

        protected long getRequestTimeout​(ServiceScheme scheme)
        Return the request timeout determined by the ServiceScheme.
        Parameters:
        scheme - the scheme that determines the request timeout
        Returns:
        the request timeout
      • isDisposed

        public boolean isDisposed()
        Return true if this factory has been disposed via invocation of dispose().
        Specified by:
        isDisposed in interface ConfigurableCacheFactory
        Returns:
        true if this factory has been disposed
      • ensureService

        public Service ensureService​(ServiceScheme scheme)
        Ensure the service for the specified scheme then start the service if it isn't running.
        Parameters:
        scheme - the scheme referring to the service
        Returns:
        the corresponding Service
      • getCacheConfig

        public CacheConfig getCacheConfig()
        Return the CacheConfig that contains the configuration used by this factory.
        Returns:
        the CacheConfig
      • translateStandardSchemeType

        protected static int translateStandardSchemeType​(String sScheme)
        Translate the scheme name into the scheme type. Valid scheme types are any of the SCHEME_* constants.
        Parameters:
        sScheme - the scheme name
        Returns:
        the scheme type
      • startServices

        public void startServices()
        Start all services that are declared as requiring an "autostart".
      • getServiceMap

        public Map<Service,​String> getServiceMap()
        Return a map of services that were successfully started by this factory where values are corresponding non-scoped service names.

        Note, that this method returns a copy of the underlying map

      • startService

        protected void startService​(Service service)
        Start the given Service. Extensions of this class can override this method to provide pre/post start functionality.
        Parameters:
        service - the Service to start
      • setConfigClassLoader

        protected void setConfigClassLoader​(ClassLoader loader)
        Set the class loader used to load the configuration for this factory.
        Parameters:
        loader - the class loader to use for loading the configuration
      • getConfigClassLoader

        protected ClassLoader getConfigClassLoader()
        Return the class loader used to load the configuration for this factory.
        Returns:
        the class loader to use for loading the configuration
      • checkPermission

        protected static void checkPermission​(NamedCache cache)
        Check if the current user is allowed to "join" the cache.
        Parameters:
        cache - the cache
      • checkPermission

        protected static void checkPermission​(NamedCollection collection)
        Check if the current user is allowed to "join" to the collection.
        Parameters:
        collection - the collection
      • checkPermission

        protected static void checkPermission​(Service service,
                                              String sName)
        Check if the current user is allowed to "join" the data structure with the specified name.
        Parameters:
        service - the service
        sName - the data structure name
      • checkContextPermission

        protected static void checkContextPermission​(NamedCache cache)
        Container aware access check to a cache.
        Parameters:
        cache - the cache
      • getParameterResolver

        public ParameterResolver getParameterResolver​(String sCacheName,
                                                      ClassLoader loader,
                                                      BackingMapManagerContext ctxBMM,
                                                      ContainerContext ctxContainer)
        Return the ParameterResolver that has been initialized with the built-in Coherence parameters. Schemes may use expressions (macros) and the resolver contains the parameters that are defined in the cache mapping needed to translate those expressions into values.
        Parameters:
        sCacheName - the cache name
        loader - the ClassLoader
        ctxBMM - the BackingMapManagerContext
        ctxContainer - the ContainerContext
        Returns:
        the ParameterResolver
      • getParameterResolver

        public <M extends ResourceMappingParameterResolver getParameterResolver​(String sResourceName,
                                                                                  Class<M> clzResourceMapping,
                                                                                  ClassLoader loader,
                                                                                  BackingMapManagerContext ctxBMM,
                                                                                  ContainerContext ctxContainer)
        Return the ParameterResolver that has been initialized with the built-in Coherence parameters. Schemes may use expressions (macros) and the resolver contains the parameters that are defined in the cache mapping needed to translate those expressions into values.
        Parameters:
        sResourceName - the resource name
        clzResourceMapping - resource type
        loader - the ClassLoader
        ctxBMM - the BackingMapManagerContext
        ctxContainer - the ContainerContext
        Returns:
        the ParameterResolver
        Since:
        14.1.1.0
      • createParameterResolver

        public ParameterResolver createParameterResolver​(ClassLoader loader,
                                                         BackingMapManagerContext ctxBMM)
        Return the ParameterResolver that has been initialized with the built-in Coherence parameters. Schemes may use expressions (macros) and the resolver contains the parameters that are defined for components defined at a scheme level and not a cache level.
        Parameters:
        loader - the ClassLoader
        ctxBMM - the BackingMapManagerContext
        Returns:
        the ParameterResolver
      • registerBackingMapManager

        protected void registerBackingMapManager​(BackingMapManager mgr)
        Register the specified BackingMapManager as a "valid" one. That registry is used to identify services configured and started by this factory and prevent accidental usage of (potentially incompatible) cache services with the same name created by other factories.
        Parameters:
        mgr - a BackingMapManager instance instantiated by this factory
      • validateBackingMapManager

        protected void validateBackingMapManager​(CacheService service)
                                          throws IllegalStateException
        Ensures that the backing map manager of the specified service was configured by this (or equivalent) factory. This validation is performed to prevent accidental usage of (potentially incompatible) cache services with the same name created by other factories.
        Parameters:
        service - the CacheService to validate
        Throws:
        IllegalStateException - if the backing map for the provided service does not reference the expected factory
      • release

        protected void release​(Map map,
                               Map mapListeners)
        Release all resources associated with the specified backing map.
        Parameters:
        map - the map being released
        mapListeners - map of registered map listeners keyed by the corresponding map references
      • release

        protected void release​(CacheLoader loader)
        Release all resources associated with the specified loader.
        Parameters:
        loader - the cache loader being released
      • release

        protected void release​(BinaryStore store)
        Release all resources associated with the specified binary store.
        Parameters:
        store - the binary store being released
      • releaseCache

        protected void releaseCache​(NamedCache cache,
                                    boolean fDestroy)
        Release a cache managed by this factory, optionally destroying it.
        Parameters:
        cache - the cache to release
        fDestroy - true to destroy the cache as well
      • releaseTopic

        public void releaseTopic​(NamedTopic<?> topic)
        Release a NamedTopic and its associated resources.

        Releasing a topic makes it no longer usable, but does not affect the topic itself. In other words, all other references to the topic will still be valid, and the topic data is not affected by releasing the reference. Any attempt to use the released topic reference afterword will result in an exception.

        Specified by:
        releaseTopic in interface ConfigurableCacheFactory
        Parameters:
        topic - the topic to release
      • destroyTopic

        public void destroyTopic​(NamedTopic<?> topic)
        Release and destroy this instance of NamedTopic.

        Warning: This method is used to completely destroy the specified topic across the cluster. All references in the entire cluster to this topic will be invalidated, the topic data will be cleared, and all internal and associated resources will be released.

        Specified by:
        destroyTopic in interface ConfigurableCacheFactory
        Parameters:
        topic - the topic to release