[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/jmx ...
Brian Stansberry
brian.stansberry at jboss.com
Sun Nov 12 23:41:47 EST 2006
User: bstansberry
Date: 06/11/12 23:41:47
Modified: src-50/org/jboss/cache/pojo/jmx PojoCacheJmxWrapper.java
Log:
Remove self registration
Revision Changes Path
1.4 +20 -102 JBossCache/src-50/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheJmxWrapper.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- PojoCacheJmxWrapper.java 10 Nov 2006 02:48:46 -0000 1.3
+++ PojoCacheJmxWrapper.java 13 Nov 2006 04:41:47 -0000 1.4
@@ -2,7 +2,6 @@
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.apache.commons.logging.Log;
@@ -11,6 +10,7 @@
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.jmx.CacheJmxWrapper;
import org.jboss.cache.jmx.CacheJmxWrapperMBean;
+import org.jboss.cache.pojo.jmx.JmxUtil;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheAlreadyDetachedException;
import org.jboss.cache.pojo.PojoCacheFactory;
@@ -25,7 +25,6 @@
private Configuration config;
private MBeanServer server;
private String cacheObjectName;
- private boolean selfRegister;
private boolean selfConstructed;
private PojoCache cache_;
private CacheJmxWrapper plainCacheWrapper_;
@@ -71,16 +70,19 @@
public void create() throws Exception
{
if (cache_ == null)
+ {
+ if (config == null)
+ {
+ throw new ConfigurationException("Must call setConfiguration() " +
+ "or setCache() before call to create()");
+ }
+
constructCache();
+ }
if (selfConstructed)
cache_.create();
- if (selfRegister)
- {
- registerWithMBeanServer();
- }
-
created = true;
}
@@ -101,11 +103,6 @@
if (selfConstructed)
cache_.destroy();
- if (selfRegister)
- {
- unregisterWithMBeanServer();
- }
-
created = false;
}
@@ -144,16 +141,8 @@
if (cacheObjectName == null)
{
- if (objName == null)
- {
- // Calling this will create a value for cacheObjectName
- getPojoCacheObjectName();
- }
- else
- {
cacheObjectName = objName.getCanonicalName();
}
- }
return new ObjectName(cacheObjectName);
}
@@ -171,10 +160,10 @@
if (config.getServiceName() == null || config.getServiceName().length() == 0)
{
// We need to inject the object name into the plain cache
- String plainName = JmxUtil.getPlainCacheObjectName(getPojoCacheObjectName());
+ String plainName = JmxUtil.getPlainCacheObjectName(cacheObjectName);
plainCacheWrapper_.setCacheObjectName(plainName);
}
- plainCacheWrapper_.registerWithBeanServer();
+ org.jboss.cache.jmx.JmxUtil.registerCacheMBean(server, plainCacheWrapper_, plainCacheWrapper_.getCacheObjectName());
}
catch (Exception e)
{
@@ -198,7 +187,14 @@
{
if (registerPlainCache)
{
- plainCacheWrapper_.unregisterMBeans();
+ try
+ {
+ org.jboss.cache.jmx.JmxUtil.unregisterCacheMBean(server, plainCacheWrapper_.getCacheObjectName());
+ }
+ catch (Exception e)
+ {
+ log.error("Could not unregister plain cache", e);
+ }
}
}
@@ -224,62 +220,10 @@
this.config = (cache == null ? null : cache.getCache().getConfiguration());
}
- /**
- * Get the name under which this object should be registered in JMX.
- *
- * @deprecated Self-registration is a temporary workaround that will be removed.
- */
- public String getPojoCacheObjectName()
- {
- if (cacheObjectName == null)
- {
- cacheObjectName = JmxUtil.getPojoCacheObjectName(cache_);
- }
- return cacheObjectName;
- }
-
- /**
- * Sets the name under which this object should be registered in JMX.
- *
- * @deprecated Self-registration is a temporary workaround that will be removed.
- */
- public void setPojoCacheObjectName(String name) throws MalformedObjectNameException
- {
- if (name != null)
- {
- // test the name
- new ObjectName(name);
- }
- this.cacheObjectName = name;
- }
-
- /**
- * 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.
- *
- * @deprecated Self-registration is a temporary workaround that will be removed.
- */
- public void setMbeanServer(MBeanServer server)
- {
- this.server = server;
- selfRegister = (server != null);
- }
-
// --------------------------------------------------------------- Private methods
private void constructCache() throws ConfigurationException
{
- Configuration config = getConfiguration();
- if (config != null)
- {
- config.setExposeManagementStatistics(false);
- }
- else
- {
- throw new ConfigurationException("Must call setConfiguration() before call to create()");
- }
-
cache_ = (PojoCacheImpl) PojoCacheFactory.createCache(config, false);
if (plainCacheWrapper_ == null)
@@ -289,35 +233,9 @@
}
plainCacheWrapper_.setRegisterInterceptors(getRegisterInterceptors());
- plainCacheWrapper_.setMbeanServer(server);
plainCacheWrapper_.setCache(cache_.getCache());
selfConstructed = true;
}
- private void registerWithMBeanServer() throws Exception
- {
- if (server != null)
- {
- JmxUtil.registerPojoCache(server, this, getPojoCacheObjectName());
- }
- else
- {
- log.warn("No MBeanServer assigned; cannot register with MBeanServer");
- }
- }
-
- private void unregisterWithMBeanServer()
- {
- try
- {
- if (server != null)
- JmxUtil.unregisterPojoCache(server, getPojoCacheObjectName());
- }
- catch (Exception e)
- {
- log.error("Exception unregistering pojo cache" ,e);
- }
- }
-
}
More information about the jboss-cvs-commits
mailing list