Class ContainerAdapter
- java.lang.Object
-
- com.tangosol.application.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 implementExtensibleConfigurableCacheFactory
).After creating an instance of ContainerAdapter. the container should call
activate()
to start the application anddeactivate()
to stop it.- Since:
- Coherence 12.1.2
- Author:
- cf 2011.05.24
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ContainerAdapter.CoherenceFactory
A factory for producing aCoherence
instance.protected class
ContainerAdapter.ContainerCacheFactoryBuilder
ContainerCacheFactoryBuilder creates aConfigurableCacheFactory
instance using the knowledge from this ContainerAdapter instance.static class
ContainerAdapter.DefaultCoherenceFactory
A default implementation of aContainerAdapter.CoherenceFactory
.static class
ContainerAdapter.DefaultContext
TheContainerAdapter.DefaultContext
represents the context for an application.
-
Field Summary
Fields Modifier and Type Field Description protected static String
CACHE_URI_DEFAULT
Internally used "default" URI identifier.protected ServiceMonitor
f_serviceMonitor
TheServiceMonitor
to use.protected ContainerAdapter.ContainerCacheFactoryBuilder
m_builder
TheContainerAdapter.ContainerCacheFactoryBuilder
used to create aConfigurableCacheFactory
for the application.protected Coherence
m_coherence
The Coherence instance.protected ContainerContext
m_containerCtx
The ContainerContext.protected ContainerAdapter.DefaultContext
m_context
TheContext
for the application.protected boolean
m_fActivated
Indicates whether the ContainerAdapter has been activated or not.protected ExtensibleConfigurableCacheFactory
m_factory
TheConfigurableCacheFactory
for the application.protected boolean
m_fExclusiveMonitor
Indicates whether the ServiceMonitor has been exclusively created for this ContainerAdapter.protected LifecycleListener
m_listener
TheLifecycleListener
used for lifecycle callbacks to the application.protected List<LifecycleListener>
m_listLifecycleListener
TheLifecycleListener
s to be notified of lifecycle events for thisContainerAdapter
.protected ClassLoader
m_loader
TheClassLoader
for the application.protected ClassLoader
m_loaderCtx
The caller's thread contextClassLoader
.protected String
m_sAppDescriptorURI
The URI to the coherence-application.xml file.protected String
m_sAppName
The name of the application.protected XmlElement
m_xmlAppDescriptor
TheXmlElement
representing the application descriptor.
-
Constructor Summary
Constructors Constructor Description ContainerAdapter(ClassLoader loader, String sAppDescriptorURI, String sAppName)
Construct the ContainerAdapter.ContainerAdapter(ClassLoader loader, String sAppDescriptorURI, String sAppName, CacheFactoryBuilder builder, XmlElement xmlAppDescriptor, ServiceMonitor serviceMonitor)
Construct the ContainerAdapter.ContainerAdapter(ClassLoader loader, String sAppDescriptorURI, String sAppName, XmlElement xmlAppDescriptor)
Construct the ContainerAdapter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activate()
Initialize and start the application that is hosted by this ContainerAdapter.void
associateWithClassLoader(ClassLoader[] aClassLoaders)
Associates the application hosted by this ContainerAdapter with specifiedClassLoader
s.void
deactivate()
Deactivate the application hosted by this ContainerAdapter.void
deactivate(boolean fShutdown)
Deactivate the application hosted by this ContainerAdapter.protected void
ensureContextClassLoader()
Ensure that the thread context ClassLoader is set to the ContainerAdapter's ClassLoader; save the current thread context ClassLoader if necessary.protected static XmlElement
extractFactoryConfig(XmlElement xmlAppDescriptor)
Extract theXmlElement
representing the factory for theConfigurableCacheFactory
instance.Context
getApplicationContext()
Return theContext
for the application.ContainerContext
getContainerContext()
Return theContainerContext
used by this ContainerAdapter.ClassLoader
getContextClassLoader()
Return the ClassLoader used by this ContainerAdapter.protected List<LifecycleListener>
getLifecycleListeners()
Returns an unmodifiable list ofLifecycleListener
s registered for thisContainerAdapter
.protected void
restoreContextClassLoader()
Restore the thread contextClassLoader
for the caller.void
setCoherenceFactory(ContainerAdapter.CoherenceFactory factory)
Set theContainerAdapter.CoherenceFactory
to use to createCoherence
instances.void
setContainerContext(ContainerContext ctx)
Set the ContainerContext associated with this ContainerAdapter instance.
-
-
-
Field Detail
-
CACHE_URI_DEFAULT
protected static final String CACHE_URI_DEFAULT
Internally used "default" URI identifier.- See Also:
- Constant Field Values
-
f_serviceMonitor
protected final ServiceMonitor f_serviceMonitor
TheServiceMonitor
to use.
-
m_builder
protected ContainerAdapter.ContainerCacheFactoryBuilder m_builder
TheContainerAdapter.ContainerCacheFactoryBuilder
used to create aConfigurableCacheFactory
for the application.
-
m_factory
protected ExtensibleConfigurableCacheFactory m_factory
TheConfigurableCacheFactory
for the application.
-
m_coherence
protected Coherence m_coherence
The Coherence instance.
-
m_loader
protected ClassLoader m_loader
TheClassLoader
for the application.
-
m_sAppDescriptorURI
protected String m_sAppDescriptorURI
The URI to the coherence-application.xml file.
-
m_xmlAppDescriptor
protected XmlElement m_xmlAppDescriptor
TheXmlElement
representing the application descriptor.
-
m_sAppName
protected String m_sAppName
The name of the application.
-
m_containerCtx
protected ContainerContext m_containerCtx
The ContainerContext.
-
m_listener
protected LifecycleListener m_listener
TheLifecycleListener
used for lifecycle callbacks to the application.
-
m_listLifecycleListener
protected List<LifecycleListener> m_listLifecycleListener
TheLifecycleListener
s to be notified of lifecycle events for thisContainerAdapter
.The
LifecycleListener
s will be discovered and loaded using theServiceLoader
.
-
m_context
protected ContainerAdapter.DefaultContext m_context
TheContext
for the application.
-
m_loaderCtx
protected ClassLoader m_loaderCtx
The caller's thread contextClassLoader
.
-
m_fActivated
protected boolean m_fActivated
Indicates whether the ContainerAdapter has been activated or not.
-
m_fExclusiveMonitor
protected boolean m_fExclusiveMonitor
Indicates whether the ServiceMonitor has been exclusively created for this ContainerAdapter.
-
-
Constructor Detail
-
ContainerAdapter
public ContainerAdapter(ClassLoader loader, String sAppDescriptorURI, String sAppName)
Construct the ContainerAdapter.- Parameters:
loader
- theClassLoader
for the applicationsAppDescriptorURI
- the URI to coherence-application.xmlsAppName
- the name of the application
-
ContainerAdapter
public ContainerAdapter(ClassLoader loader, String sAppDescriptorURI, String sAppName, XmlElement xmlAppDescriptor)
Construct the ContainerAdapter.- Parameters:
loader
- theClassLoader
for the applicationsAppDescriptorURI
- the URI to coherence-application.xmlsAppName
- the name of the applicationxmlAppDescriptor
- theXmlElement
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
- theClassLoader
for the applicationsAppDescriptorURI
- the URI to the application configuration descriptorsAppName
- the name of the applicationbuilder
- theCacheFactoryBuilder
to usexmlAppDescriptor
- theXmlElement
containing the application descriptor; if not null it will be used instead of the configuration specified by sAppDescriptorURIserviceMonitor
- theServiceMonitor
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. IffShutdown
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 specifiedClassLoader
s.- Parameters:
aClassLoaders
- an array ofClassLoader
s 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 theContext
for the application.- Returns:
- the
Context
for the application
-
getContainerContext
public ContainerContext getContainerContext()
Return theContainerContext
used by this ContainerAdapter.- Returns:
- the
ContainerContext
used by this ContainerAdapter.
-
setCoherenceFactory
public void setCoherenceFactory(ContainerAdapter.CoherenceFactory factory)
Set theContainerAdapter.CoherenceFactory
to use to createCoherence
instances.- Parameters:
factory
- theContainerAdapter.CoherenceFactory
to use to createCoherence
instances
-
getLifecycleListeners
protected List<LifecycleListener> getLifecycleListeners()
Returns an unmodifiable list ofLifecycleListener
s registered for thisContainerAdapter
.If the list of listeners does not yet exist it will be created and initially populated using the
ServiceLoader
to discover and load listeners.- Returns:
- the list of
LifecycleListener
s registered for thisContainerAdapter
-
extractFactoryConfig
protected static XmlElement extractFactoryConfig(XmlElement xmlAppDescriptor)
Extract theXmlElement
representing the factory for theConfigurableCacheFactory
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 contextClassLoader
for the caller.
-
-