Class ContainerAdapter


  • public class ContainerAdapter
    extends Object
    ContainerAdapter is a facility intended for use by application servers to host Coherence applications. This facility manages the application life cycle and configuration.

    The application descriptor file (coherence-application.xml) contains the location of a cache configuration file and (optionally) a POF configuration file. It may also specify the name of a ConfigurableCacheFactory class to be used to create caches instead of the system-wide default (Note that this class must implement ExtensibleConfigurableCacheFactory).

    After creating an instance of ContainerAdapter. the container should call activate() to start the application and deactivate() to stop it.

    Since:
    Coherence 12.1.2
    Author:
    cf 2011.05.24
    • Constructor Detail

      • ContainerAdapter

        public ContainerAdapter​(ClassLoader loader,
                                String sAppDescriptorURI,
                                String sAppName)
        Construct the ContainerAdapter.
        Parameters:
        loader - the ClassLoader for the application
        sAppDescriptorURI - the URI to coherence-application.xml
        sAppName - the name of the application
      • ContainerAdapter

        public ContainerAdapter​(ClassLoader loader,
                                String sAppDescriptorURI,
                                String sAppName,
                                XmlElement xmlAppDescriptor)
        Construct the ContainerAdapter.
        Parameters:
        loader - the ClassLoader for the application
        sAppDescriptorURI - the URI to coherence-application.xml
        sAppName - the name of the application
        xmlAppDescriptor - the XmlElement containing the application descriptor; if not null it will be used instead of the configuration specified by sAppDescriptorURI
      • ContainerAdapter

        public ContainerAdapter​(ClassLoader loader,
                                String sAppDescriptorURI,
                                String sAppName,
                                CacheFactoryBuilder builder,
                                XmlElement xmlAppDescriptor,
                                ServiceMonitor serviceMonitor)
        Construct the ContainerAdapter.
        Parameters:
        loader - the ClassLoader for the application
        sAppDescriptorURI - the URI to the application configuration descriptor
        sAppName - the name of the application
        builder - the CacheFactoryBuilder to use
        xmlAppDescriptor - the XmlElement containing the application descriptor; if not null it will be used instead of the configuration specified by sAppDescriptorURI
        serviceMonitor - the ServiceMonitor to use for the application
    • Method Detail

      • setContainerContext

        public void setContainerContext​(ContainerContext ctx)
        Set the ContainerContext associated with this ContainerAdapter instance.

        This method must be called before the adapter is activated.

        Parameters:
        ctx - the ContainerContext reference
      • activate

        public void activate()
        Initialize and start the application that is hosted by this ContainerAdapter.

        If this method throws an exception, the caller is NOT required to call deactivate().

        Throws:
        IllegalStateException - if the application has already been activated
      • deactivate

        public void deactivate()
        Deactivate the application hosted by this ContainerAdapter. This method will shut down any resources / Coherence services that were used by the application.
        Throws:
        IllegalStateException - if the application is not active
      • deactivate

        public void deactivate​(boolean fShutdown)
        Deactivate the application hosted by this ContainerAdapter. If fShutdown is true shutdown any resources / Coherence services that were used by the application otherwise clear local references.
        Parameters:
        fShutdown - whether to shut down the resources, incl. any services, that were started as a part of this application
        Throws:
        IllegalStateException - if the application is not active
      • associateWithClassLoader

        public void associateWithClassLoader​(ClassLoader[] aClassLoaders)
        Associates the application hosted by this ContainerAdapter with specified ClassLoaders.
        Parameters:
        aClassLoaders - an array of ClassLoaders to associate this adapter with
      • getContextClassLoader

        public ClassLoader getContextClassLoader()
        Return the ClassLoader used by this ContainerAdapter.
        Returns:
        the ClassLoader used by this ContainerAdapter
      • getApplicationContext

        public Context getApplicationContext()
        Return the Context for the application.
        Returns:
        the Context for the application
      • extractFactoryConfig

        protected static XmlElement extractFactoryConfig​(XmlElement xmlAppDescriptor)
        Extract the XmlElement representing the factory for the ConfigurableCacheFactory instance.
        Parameters:
        xmlAppDescriptor - the application descriptor XML element
        Returns:
        the XmlElement representing the factory or null if no element exists.
      • ensureContextClassLoader

        protected void ensureContextClassLoader()
        Ensure that the thread context ClassLoader is set to the ContainerAdapter's ClassLoader; save the current thread context ClassLoader if necessary.
      • restoreContextClassLoader

        protected void restoreContextClassLoader()
        Restore the thread context ClassLoader for the caller.