[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/impl ...
Ben Wang
bwang at jboss.com
Mon Sep 25 01:50:05 EDT 2006
User: bwang
Date: 06/09/25 01:50:05
Modified: src-50/org/jboss/cache/pojo/impl PojoCacheImpl.java
Log:
1. Modify useInterceptorMbeans to useMbean
2. Added PojoCache jmx framework
3. added test
Revision Changes Path
1.22 +51 -7 JBossCache/src-50/org/jboss/cache/pojo/impl/PojoCacheImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/PojoCacheImpl.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- PojoCacheImpl.java 19 Sep 2006 02:32:02 -0000 1.21
+++ PojoCacheImpl.java 25 Sep 2006 05:50:05 -0000 1.22
@@ -22,6 +22,7 @@
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.PojoCacheListener;
+import org.jboss.cache.pojo.jmx.JmxUtil;
import org.jboss.cache.pojo.util.AopUtil;
import org.jboss.cache.pojo.annotation.Attach;
import org.jboss.cache.pojo.annotation.Detach;
@@ -31,6 +32,7 @@
import org.jboss.aop.proxy.ClassProxy;
import org.jboss.aop.Advised;
+import javax.management.MBeanServer;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
@@ -43,16 +45,17 @@
* Implementation class for PojoCache interface
*
* @author Ben Wang
- * @version $Id: PojoCacheImpl.java,v 1.21 2006/09/19 02:32:02 bwang Exp $
+ * @version $Id: PojoCacheImpl.java,v 1.22 2006/09/25 05:50:05 bwang Exp $
*/
public class PojoCacheImpl implements PojoCache, Observer
{
private CacheSPI cache_ = null;
- protected final Log log = LogFactory.getLog(PojoCacheImpl.this.getClass());
+ protected final Log log_ = LogFactory.getLog(PojoCacheImpl.this.getClass());
private PojoCacheDelegate delegate_;
// Class -> CachedType
// use WeakHashMap to allow class reloading
- private Map cachedTypes = new WeakHashMap();
+ private Map cachedTypes_ = new WeakHashMap();
+ private boolean hasCreate_ = false;
/**
* Set of TreeCacheListener.
@@ -226,7 +229,7 @@
public void create() throws PojoCacheException
{
- log.info("PojoCache version: " + getVersion());
+ log_.info("PojoCache version: " + getVersion());
try
{
cache_.create();
@@ -234,13 +237,36 @@
{
throw new PojoCacheException("PojoCache create exception", e);
}
+
+ if(cache_.getConfiguration().isUseMbean())
+ {
+ MBeanServer mbserver = JmxUtil.getMBeanServer();
+ if (mbserver != null)
+ {
+ try
+ {
+ JmxUtil.registerPojoCache(mbserver, this);
+ } catch (Exception e)
+ {
+ throw new PojoCacheException("Exception in MBean registration", e);
+ }
+ }
+
+ }
+
+ hasCreate_ = true;
}
public void start() throws PojoCacheException
{
+ if(!hasCreate_)
+ {
+ create();
+ }
+
try
{
- log.info("PojoCache version: " + getVersion());
+ log_.info("PojoCache version: " + getVersion());
cache_.start();
} catch (Exception e)
{
@@ -257,6 +283,24 @@
public void destroy() throws PojoCacheException
{
cache_.destroy();
+
+ // unregister interceptor mbeans
+ if (cache_.getConfiguration().isUseMbean())
+ {
+ MBeanServer mbserver = JmxUtil.getMBeanServer();
+ if (mbserver != null)
+ {
+ try
+ {
+ JmxUtil.unregisterPojoCache(mbserver, this);
+ }
+ catch (Exception e)
+ {
+ new PojoCacheException("failed unregistering PojoCache mbean ", e);
+ }
+ }
+ }
+
}
public void addListener(PojoCacheListener listener)
@@ -321,11 +365,11 @@
*/
public synchronized CachedType getCachedType(Class clazz)
{
- CachedType type = (CachedType) cachedTypes.get(clazz);
+ CachedType type = (CachedType) cachedTypes_.get(clazz);
if (type == null)
{
type = new CachedType(clazz);
- cachedTypes.put(clazz, type);
+ cachedTypes_.put(clazz, type);
return type;
} else
{
More information about the jboss-cvs-commits
mailing list