public class ManagementService extends Object implements CacheManagerEventListener
net.sf.ehcache.constructs.web.ShutdownListener
}
enables this to be detected and the CacheManager shutdown.
When a CacheManager is shut down we need to ensure there is no memory, resource or
thread leakage. An MBeanServer, particularly a platform MBeanServer, can be expected
to exist for the lifespan of the JVM. Accordingly, we need to deregister them when
needed without creating a leakage.
The second purpose of this class (and this package) is to keep management concerns away
from the core ehcache packages. That way, JMX is not a required dependency, but rather
an optional one.
This class is constructable as of 1.5 to support injection via IoC containers.Constructor and Description |
---|
ManagementService(CacheManager cacheManager,
MBeanServer mBeanServer,
boolean registerCacheManager,
boolean registerCaches,
boolean registerCacheConfigurations,
boolean registerCacheStatistics)
A constructor for a management service for a range of possible MBeans.
|
ManagementService(CacheManager cacheManager,
MBeanServer mBeanServer,
boolean registerCacheManager,
boolean registerCaches,
boolean registerCacheConfigurations,
boolean registerCacheStatistics,
boolean registerCacheStores)
A constructor for a management service for a range of possible MBeans.
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Stop the listener and free any resources.
|
Status |
getStatus()
Returns the listener status.
|
void |
init()
Call to register the mbeans in the mbean server and start the event listeners and do any other required initialisation.
|
void |
notifyCacheAdded(String cacheName)
Called immediately after a cache has been added and activated.
|
void |
notifyCacheRemoved(String cacheName)
Called immediately after a cache has been disposed and removed.
|
static void |
registerMBeans(CacheManager cacheManager,
MBeanServer mBeanServer,
boolean registerCacheManager,
boolean registerCaches,
boolean registerCacheConfigurations,
boolean registerCacheStatistics)
A convenience static method which creates a ManagementService and initialises it with the
supplied parameters.
|
static void |
registerMBeans(CacheManager cacheManager,
MBeanServer mBeanServer,
boolean registerCacheManager,
boolean registerCaches,
boolean registerCacheConfigurations,
boolean registerCacheStatistics,
boolean registerCacheStores)
A convenience static method which creates a ManagementService and initialises it with the
supplied parameters.
|
public ManagementService(CacheManager cacheManager, MBeanServer mBeanServer, boolean registerCacheManager, boolean registerCaches, boolean registerCacheConfigurations, boolean registerCacheStatistics, boolean registerCacheStores) throws CacheException
init()
method needs to be called after construction which causes
the selected monitoring options to be be registered
with the provided MBeanServer for caches in the given CacheManager.
While registering the CacheManager enables traversal to all of the other
items,
this requires programmatic traversal. The other options allow entry points closer
to an item of interest and are more accessible from JMX management tools like JConsole.
Moreover CacheManager and Cache are not serializable, so remote monitoring is not possible
for CacheManager or Cache, while CacheStatistics and CacheConfiguration are. Finally
CacheManager and Cache enable management operations to be performed.
Once monitoring is enabled caches will automatically added and removed from the MBeanServer
as they are added and disposed of from the CacheManager. When the CacheManager itself
shutsdown all registered MBeans will be unregistered.cacheManager
- the CacheManager to listen tomBeanServer
- the MBeanServer to register MBeans toregisterCacheManager
- Whether to register the CacheManager MBeanregisterCaches
- Whether to register the Cache MBeansregisterCacheConfigurations
- Whether to register the CacheConfiguration MBeansregisterCacheStatistics
- Whether to register the CacheStatistics MBeansCacheException
- if something goes wrong with init()public ManagementService(CacheManager cacheManager, MBeanServer mBeanServer, boolean registerCacheManager, boolean registerCaches, boolean registerCacheConfigurations, boolean registerCacheStatistics) throws CacheException
init()
method needs to be called after construction which causes
the selected monitoring options to be be registered
with the provided MBeanServer for caches in the given CacheManager.
While registering the CacheManager enables traversal to all of the other
items,
this requires programmatic traversal. The other options allow entry points closer
to an item of interest and are more accessible from JMX management tools like JConsole.
Moreover CacheManager and Cache are not serializable, so remote monitoring is not possible
for CacheManager or Cache, while CacheStatistics and CacheConfiguration are. Finally
CacheManager and Cache enable management operations to be performed.
Once monitoring is enabled caches will automatically added and removed from the MBeanServer
as they are added and disposed of from the CacheManager. When the CacheManager itself
shutsdown all registered MBeans will be unregistered.cacheManager
- the CacheManager to listen tomBeanServer
- the MBeanServer to register MBeans toregisterCacheManager
- Whether to register the CacheManager MBeanregisterCaches
- Whether to register the Cache MBeansregisterCacheConfigurations
- Whether to register the CacheConfiguration MBeansregisterCacheStatistics
- Whether to register the CacheStatistics MBeansCacheException
- if something goes wrong with init()public static void registerMBeans(CacheManager cacheManager, MBeanServer mBeanServer, boolean registerCacheManager, boolean registerCaches, boolean registerCacheConfigurations, boolean registerCacheStatistics, boolean registerCacheStores) throws CacheException
cacheManager
- the CacheManager to listen tomBeanServer
- the MBeanServer to register MBeans toregisterCacheManager
- Whether to register the CacheManager MBeanregisterCaches
- Whether to register the Cache MBeansregisterCacheConfigurations
- Whether to register the CacheConfiguration MBeansregisterCacheStatistics
- Whether to register the CacheStatistics MBeansCacheException
ManagementService(net.sf.ehcache.CacheManager, javax.management.MBeanServer, boolean, boolean, boolean, boolean, boolean)
public static void registerMBeans(CacheManager cacheManager, MBeanServer mBeanServer, boolean registerCacheManager, boolean registerCaches, boolean registerCacheConfigurations, boolean registerCacheStatistics) throws CacheException
cacheManager
- the CacheManager to listen tomBeanServer
- the MBeanServer to register MBeans toregisterCacheManager
- Whether to register the CacheManager MBeanregisterCaches
- Whether to register the Cache MBeansregisterCacheConfigurations
- Whether to register the CacheConfiguration MBeansregisterCacheStatistics
- Whether to register the CacheStatistics MBeansCacheException
ManagementService(net.sf.ehcache.CacheManager, javax.management.MBeanServer, boolean, boolean, boolean, boolean)
public void init() throws CacheException
init
in interface CacheManagerEventListener
CacheException
- - all exceptions are wrapped in CacheExceptionpublic Status getStatus()
getStatus
in interface CacheManagerEventListener
public void dispose() throws CacheException
dispose
in interface CacheManagerEventListener
CacheException
- - all exceptions are wrapped in CacheExceptionpublic void notifyCacheAdded(String cacheName)
Status.STATUS_UNINITIALISED
to
Status.STATUS_ALIVE
. Care should be taken on processing that
notification because:
CacheManager.getEhcache(String)
will cause a deadlock.
notifyCacheAdded
in interface CacheManagerEventListener
cacheName
- the name of the Cache
the operation relates toCacheEventListener
public void notifyCacheRemoved(String cacheName)
CacheEventListener
status changed will also be triggered. Any
attempt from that notification to access CacheManager will also result in a deadlock.notifyCacheRemoved
in interface CacheManagerEventListener
cacheName
- the name of the Cache
the operation relates toCopyright © 2003–2016 Terracotta, Inc.. All rights reserved.