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.
| Modifier and Type | Field and Description |
|---|---|
| private final CacheManager | |
| private static final Logger | |
| private final MBeanServer | |
| private final boolean | |
| private final boolean | |
| private final boolean | |
| private final boolean | |
| private final boolean | |
| private Status |
| Access | Constructor and Description |
|---|---|
| public | ManagementService(CacheManager
the CacheManager to listen to cacheManager, MBeanServer the MBeanServer to register MBeans to mBeanServer, boolean Whether to register the CacheManager MBean registerCacheManager, boolean Whether to register the Cache MBeans registerCaches, boolean Whether to register the CacheConfiguration MBeans registerCacheConfigurations, boolean Whether to register the CacheStatistics MBeans registerCacheStatistics, boolean registerCacheStores)A constructor for a management service for a range of possible MBeans. |
| public | ManagementService(CacheManager
the CacheManager to listen to cacheManager, MBeanServer the MBeanServer to register MBeans to mBeanServer, boolean Whether to register the CacheManager MBean registerCacheManager, boolean Whether to register the Cache MBeans registerCaches, boolean Whether to register the CacheConfiguration MBeans registerCacheConfigurations, boolean Whether to register the CacheStatistics MBeans registerCacheStatistics)A constructor for a management service for a range of possible MBeans. |
| Modifier and Type | Method and Description |
|---|---|
| public void | dispose()
Implements net. |
| public Status | Returns: the status at the point in time the method is calledImplements net. |
| public void | init()
Implements net. |
| public void | notifyCacheAdded(String
the name of the cacheName)Cache the operation relates toImplements net. |
| public void | notifyCacheRemoved(String
the name of the cacheName)Cache the operation relates toImplements net. |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| public static void | registerMBeans(CacheManager
the CacheManager to listen to cacheManager, MBeanServer the MBeanServer to register MBeans to mBeanServer, boolean Whether to register the CacheManager MBean registerCacheManager, boolean Whether to register the Cache MBeans registerCaches, boolean Whether to register the CacheConfiguration MBeans registerCacheConfigurations, boolean Whether to register the CacheStatistics MBeans registerCacheStatistics, boolean registerCacheStores)A convenience static method which creates a ManagementService and initialises it with the supplied parameters. |
| public static void | registerMBeans(CacheManager
the CacheManager to listen to cacheManager, MBeanServer the MBeanServer to register MBeans to mBeanServer, boolean Whether to register the CacheManager MBean registerCacheManager, boolean Whether to register the Cache MBeans registerCaches, boolean Whether to register the CacheConfiguration MBeans registerCacheConfigurations, boolean Whether to register the CacheStatistics MBeans registerCacheStatistics)A convenience static method which creates a ManagementService and initialises it with the supplied parameters. |
| private void | |
| private void |
| backingCacheManager | back to summary |
|---|---|
| private final CacheManager backingCacheManager | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| mBeanServer | back to summary |
|---|---|
| private final MBeanServer mBeanServer | |
| registerCacheConfigurations | back to summary |
|---|---|
| private final boolean registerCacheConfigurations | |
| registerCacheManager | back to summary |
|---|---|
| private final boolean registerCacheManager | |
| registerCaches | back to summary |
|---|---|
| private final boolean registerCaches | |
| registerCacheStatistics | back to summary |
|---|---|
| private final boolean registerCacheStatistics | |
| registerCacheStores | back to summary |
|---|---|
| private final boolean registerCacheStores | |
| status | back to summary |
|---|---|
| private Status status | |
| ManagementService | back to summary |
|---|---|
| public ManagementService(CacheManager cacheManager, MBeanServer mBeanServer, boolean registerCacheManager, boolean registerCaches, boolean registerCacheConfigurations, boolean registerCacheStatistics, boolean registerCacheStores) throws CacheException A constructor for a management service for a range of possible MBeans.
The 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.
| |
| ManagementService | back to summary |
|---|---|
| public ManagementService(CacheManager cacheManager, MBeanServer mBeanServer, boolean registerCacheManager, boolean registerCaches, boolean registerCacheConfigurations, boolean registerCacheStatistics) throws CacheException A constructor for a management service for a range of possible MBeans.
The 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.
| |
| dispose | back to summary |
|---|---|
| public void dispose() throws CacheException Implements net. Stop the listener and free any resources. Removes registered ObjectNames
| |
| getStatus | back to summary |
|---|---|
| public Status getStatus() Implements net. Returns the listener status.
| |
| init | back to summary |
|---|---|
| public void init() throws CacheException Implements net. Call to register the mbeans in the mbean server and start the event listeners and do any other required initialisation. Once intialised, it registers itself as a CacheManageEvenListener with the backing CacheManager, so that it can participate in lifecycle and other events.
| |
| notifyCacheAdded | back to summary |
|---|---|
| public void notifyCacheAdded(String cacheName) Implements net. Called immediately after a cache has been added and activated. Note that the CacheManager calls this method from a synchronized method. Any attempt to call a synchronized method on CacheManager from this method will cause a deadlock.
Note that activation will also cause a CacheEventListener status change notification
from
| |
| notifyCacheRemoved | back to summary |
|---|---|
| public void notifyCacheRemoved(String cacheName) Implements net. Called immediately after a cache has been disposed and removed. The calling method will block until this method returns. Note that the CacheManager calls this method from a synchronized method. Any attempt to call a synchronized method on CacheManager from this method will cause a deadlock.
Note that a
| |
| registerCacheConfigurationIfRequired | back to summary |
|---|---|
| private void registerCacheConfigurationIfRequired(Cache cache) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException | |
| registerCacheManager | back to summary |
|---|---|
| private void registerCacheManager(CacheManager cacheManager) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException | |
| registerCachesIfRequired | back to summary |
|---|---|
| private void registerCachesIfRequired(Cache cache) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException | |
| registerCacheStatisticsIfRequired | back to summary |
|---|---|
| private void registerCacheStatisticsIfRequired(Cache cache) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException | |
| registerCacheStoreIfRequired | back to summary |
|---|---|
| private void registerCacheStoreIfRequired(Cache cache) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException | |
| registerMBeans | back to summary |
|---|---|
| public static void registerMBeans(CacheManager cacheManager, MBeanServer mBeanServer, boolean registerCacheManager, boolean registerCaches, boolean registerCacheConfigurations, boolean registerCacheStatistics, boolean registerCacheStores) throws CacheException A convenience static method which creates a ManagementService and initialises it with the supplied parameters.
| |
| registerMBeans | back to summary |
|---|---|
| public static void registerMBeans(CacheManager cacheManager, MBeanServer mBeanServer, boolean registerCacheManager, boolean registerCaches, boolean registerCacheConfigurations, boolean registerCacheStatistics) throws CacheException A convenience static method which creates a ManagementService and initialises it with the supplied parameters. This one is provided for backward compatibility
| |
| registerPeerProviders | back to summary |
|---|---|
| private void registerPeerProviders() | |
| unregisterMBean | back to summary |
|---|---|
| private void unregisterMBean(ObjectName objectName) | |