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
ConfigurableCacheFactoryclass 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 interfaceContainerAdapter.CoherenceFactoryA factory for producing aCoherenceinstance.protected classContainerAdapter.ContainerCacheFactoryBuilderContainerCacheFactoryBuilder creates aConfigurableCacheFactoryinstance using the knowledge from this ContainerAdapter instance.static classContainerAdapter.DefaultCoherenceFactoryA default implementation of aContainerAdapter.CoherenceFactory.static classContainerAdapter.DefaultContextTheContainerAdapter.DefaultContextrepresents the context for an application. 
- 
Field Summary
Fields Modifier and Type Field Description protected static StringCACHE_URI_DEFAULTInternally used "default" URI identifier.protected ServiceMonitorf_serviceMonitorTheServiceMonitorto use.protected ContainerAdapter.ContainerCacheFactoryBuilderm_builderTheContainerAdapter.ContainerCacheFactoryBuilderused to create aConfigurableCacheFactoryfor the application.protected Coherencem_coherenceThe Coherence instance.protected ContainerContextm_containerCtxThe ContainerContext.protected ContainerAdapter.DefaultContextm_contextTheContextfor the application.protected booleanm_fActivatedIndicates whether the ContainerAdapter has been activated or not.protected ExtensibleConfigurableCacheFactorym_factoryTheConfigurableCacheFactoryfor the application.protected booleanm_fExclusiveMonitorIndicates whether the ServiceMonitor has been exclusively created for this ContainerAdapter.protected LifecycleListenerm_listenerTheLifecycleListenerused for lifecycle callbacks to the application.protected List<LifecycleListener>m_listLifecycleListenerTheLifecycleListeners to be notified of lifecycle events for thisContainerAdapter.protected ClassLoaderm_loaderTheClassLoaderfor the application.protected ClassLoaderm_loaderCtxThe caller's thread contextClassLoader.protected Stringm_sAppDescriptorURIThe URI to the coherence-application.xml file.protected Stringm_sAppNameThe name of the application.protected XmlElementm_xmlAppDescriptorTheXmlElementrepresenting 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 voidactivate()Initialize and start the application that is hosted by this ContainerAdapter.voidassociateWithClassLoader(ClassLoader[] aClassLoaders)Associates the application hosted by this ContainerAdapter with specifiedClassLoaders.voiddeactivate()Deactivate the application hosted by this ContainerAdapter.voiddeactivate(boolean fShutdown)Deactivate the application hosted by this ContainerAdapter.protected voidensureContextClassLoader()Ensure that the thread context ClassLoader is set to the ContainerAdapter's ClassLoader; save the current thread context ClassLoader if necessary.protected static XmlElementextractFactoryConfig(XmlElement xmlAppDescriptor)Extract theXmlElementrepresenting the factory for theConfigurableCacheFactoryinstance.ContextgetApplicationContext()Return theContextfor the application.ContainerContextgetContainerContext()Return theContainerContextused by this ContainerAdapter.ClassLoadergetContextClassLoader()Return the ClassLoader used by this ContainerAdapter.protected List<LifecycleListener>getLifecycleListeners()Returns an unmodifiable list ofLifecycleListeners registered for thisContainerAdapter.protected voidrestoreContextClassLoader()Restore the thread contextClassLoaderfor the caller.voidsetCoherenceFactory(ContainerAdapter.CoherenceFactory factory)Set theContainerAdapter.CoherenceFactoryto use to createCoherenceinstances.voidsetContainerContext(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
TheServiceMonitorto use. 
- 
m_builder
protected ContainerAdapter.ContainerCacheFactoryBuilder m_builder
TheContainerAdapter.ContainerCacheFactoryBuilderused to create aConfigurableCacheFactoryfor the application. 
- 
m_factory
protected ExtensibleConfigurableCacheFactory m_factory
TheConfigurableCacheFactoryfor the application. 
- 
m_coherence
protected Coherence m_coherence
The Coherence instance. 
- 
m_loader
protected ClassLoader m_loader
TheClassLoaderfor the application. 
- 
m_sAppDescriptorURI
protected String m_sAppDescriptorURI
The URI to the coherence-application.xml file. 
- 
m_xmlAppDescriptor
protected XmlElement m_xmlAppDescriptor
TheXmlElementrepresenting 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
TheLifecycleListenerused for lifecycle callbacks to the application. 
- 
m_listLifecycleListener
protected List<LifecycleListener> m_listLifecycleListener
TheLifecycleListeners to be notified of lifecycle events for thisContainerAdapter.The
LifecycleListeners will be discovered and loaded using theServiceLoader. 
- 
m_context
protected ContainerAdapter.DefaultContext m_context
TheContextfor 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- theClassLoaderfor 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- theClassLoaderfor the applicationsAppDescriptorURI- the URI to coherence-application.xmlsAppName- the name of the applicationxmlAppDescriptor- theXmlElementcontaining 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- theClassLoaderfor the applicationsAppDescriptorURI- the URI to the application configuration descriptorsAppName- the name of the applicationbuilder- theCacheFactoryBuilderto usexmlAppDescriptor- theXmlElementcontaining the application descriptor; if not null it will be used instead of the configuration specified by sAppDescriptorURIserviceMonitor- theServiceMonitorto 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. IffShutdownis 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 specifiedClassLoaders.- Parameters:
 aClassLoaders- an array ofClassLoaders 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 theContextfor the application.- Returns:
 - the 
Contextfor the application 
 
- 
getContainerContext
public ContainerContext getContainerContext()
Return theContainerContextused by this ContainerAdapter.- Returns:
 - the 
ContainerContextused by this ContainerAdapter. 
 
- 
setCoherenceFactory
public void setCoherenceFactory(ContainerAdapter.CoherenceFactory factory)
Set theContainerAdapter.CoherenceFactoryto use to createCoherenceinstances.- Parameters:
 factory- theContainerAdapter.CoherenceFactoryto use to createCoherenceinstances
 
- 
getLifecycleListeners
protected List<LifecycleListener> getLifecycleListeners()
Returns an unmodifiable list ofLifecycleListeners registered for thisContainerAdapter.If the list of listeners does not yet exist it will be created and initially populated using the
ServiceLoaderto discover and load listeners.- Returns:
 - the list of 
LifecycleListeners registered for thisContainerAdapter 
 
- 
extractFactoryConfig
protected static XmlElement extractFactoryConfig(XmlElement xmlAppDescriptor)
Extract theXmlElementrepresenting the factory for theConfigurableCacheFactoryinstance.- Parameters:
 xmlAppDescriptor- the application descriptor XML element- Returns:
 - the 
XmlElementrepresenting 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 contextClassLoaderfor the caller. 
 - 
 
 -