[jboss-cvs] JBossCache/src/org/jboss/cache/jmx ...
Brian Stansberry
brian.stansberry at jboss.com
Sun Nov 12 23:40:38 EST 2006
User: bstansberry
Date: 06/11/12 23:40:38
Modified: src/org/jboss/cache/jmx CacheJmxWrapper.java
Log:
Remove self registration
Ensure interceptors are registered if we're registered before cache is created
Revision Changes Path
1.5 +34 -69 JBossCache/src/org/jboss/cache/jmx/CacheJmxWrapper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheJmxWrapper.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/jmx/CacheJmxWrapper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- CacheJmxWrapper.java 12 Nov 2006 06:19:47 -0000 1.4
+++ CacheJmxWrapper.java 13 Nov 2006 04:40:37 -0000 1.5
@@ -43,8 +43,8 @@
private Configuration config;
private MBeanServer server;
private String cacheObjectName;
- private boolean selfRegister = false;
private boolean selfConstructed = false;
+ private boolean registeredInterceptorsInCreate;
private boolean created;
// -------------------------------------------------------- CacheJMXWrapperMBean
@@ -61,14 +61,6 @@
public Cache getCache()
{
- if (tcpi == null)
- {
- if (config == null)
- return null;
- else
- constructCache();
- }
-
return tcpi;
}
@@ -80,14 +72,22 @@
public void create() throws Exception
{
if (tcpi == null)
+ {
+ if (config == null)
+ throw new ConfigurationException("Must call setConfiguration() or setCache()before call to create()");
+
constructCache();
+ }
if (selfConstructed)
+ {
tcpi.create();
- if (selfRegister)
+ if (server != null)
{
- registerWithBeanServer();
+ JmxUtil.registerInterceptors(server, tcpi.getInterceptorChain(), cacheObjectName);
+ registeredInterceptorsInCreate = true;
+ }
}
created = true;
@@ -108,11 +108,12 @@
public void destroy()
{
if (selfConstructed)
+ {
tcpi.destroy();
-
- if (selfRegister)
+ if (registeredInterceptorsInCreate)
{
- unregisterMBeans();
+ unregisterInterceptors();
+ }
}
created = false;
@@ -152,7 +153,7 @@
*/
public void postRegister(Boolean registrationDone)
{
- if (Boolean.TRUE.equals(registrationDone) && registerInterceptors)
+ if (Boolean.TRUE.equals(registrationDone) && registerInterceptors && tcpi != null)
{
try
{
@@ -180,14 +181,7 @@
{
if (registerInterceptors)
{
- try
- {
- JmxUtil.unregisterInterceptors(server, tcpi.getInterceptorChain(), getCacheObjectName());
- }
- catch (Exception e)
- {
- log.error("Exception unregistering interceptors from JMX", e);
- }
+ unregisterInterceptors();
}
}
@@ -211,17 +205,6 @@
}
/**
- * Provides a hook for dependency injecting the MBeanServer in environments where
- * this object will not be externally registered in JMX. If this setter is called,
- * this object will register itself in JMX during the create() phase.
- */
- public void setMbeanServer(MBeanServer server)
- {
- this.server = server;
- selfRegister = (server != null);
- }
-
- /**
* Allows direct injection of the underlying cache.
*
* @param cache
@@ -255,49 +238,31 @@
this.cacheObjectName = name;
}
- public void registerWithBeanServer() throws Exception
- {
- if (server != null)
+ // ------------------------------------------------------ Protected Methods
+
+ public MBeanServer getMBeanServer()
{
- String cacheObjectName = getCacheObjectName();
- JmxUtil.registerCacheMBean(server, this, cacheObjectName);
+ return server;
}
- else
+
+ // -------------------------------------------------------- Private methods
+
+ private void constructCache() throws Exception
{
- log.warn("No MBeanServer assigned; cannot register with MBeanServer");
- }
+ setCache(DefaultCacheFactory.createCache(config, false));
+ selfConstructed = true;
}
- public void unregisterMBeans()
- {
- if (server != null)
+ private void unregisterInterceptors()
{
try
{
- JmxUtil.unregisterCacheMBean(server, getCacheObjectName());
+ JmxUtil.unregisterInterceptors(server, tcpi.getInterceptorChain(), getCacheObjectName());
}
catch (Exception e)
{
- log.error("Exception unregistering cache from JMX", e);
- }
- }
- }
-
- // -------------------------------------------------------------- Private methods
-
- private void constructCache() throws ConfigurationException
- {
- if (config != null)
- {
- config.setExposeManagementStatistics(false);
- }
- else
- {
- throw new ConfigurationException("Must call setConfiguration() before call to create()");
+ log.error("Exception unregistering interceptors from JMX", e);
}
-
- setCache(DefaultCacheFactory.createCache(config, false));
- selfConstructed = true;
}
}
More information about the jboss-cvs-commits
mailing list