Update of /var/cvs/src/org/mmbase/cache
In directory james.mmbase.org:/tmp/cvs-serv26795

Modified Files:
        Cache.java CacheManager.java 
Added Files:
        CacheMBean.java 
Log Message:
MMB-1107, some support for JMX


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/cache
See also: http://www.mmbase.org/jira/browse/MMB-1107


CacheMBean.java is new



Index: Cache.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/cache/Cache.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- Cache.java  30 Jun 2008 08:11:08 -0000      1.52
+++ Cache.java  11 Jul 2008 12:46:44 -0000      1.53
@@ -20,9 +20,9 @@
  * A base class for all Caches. Extend this class for other caches.
  *
  * @author Michiel Meeuwissen
- * @version $Id: Cache.java,v 1.52 2008/06/30 08:11:08 michiel Exp $
+ * @version $Id: Cache.java,v 1.53 2008/07/11 12:46:44 michiel Exp $
  */
-abstract public class Cache<K, V> implements SizeMeasurable, Map<K, V> {
+abstract public class Cache<K, V> implements SizeMeasurable, Map<K, V>, 
CacheMBean {
 
     private static final Logger log = Logging.getLoggerInstance(Cache.class);
 
@@ -32,7 +32,7 @@
     /**
      * @since MMBase-1.8
      */
-    private CacheImplementationInterface<K, V> implementation;
+    CacheImplementationInterface<K, V> implementation;
     protected Object lock;
 
     /**
@@ -215,6 +215,9 @@
     public  int maxSize() {
         return implementation.maxSize();
     }
+    public int getMaxSize() {
+        return maxSize();
+    }
 
     /**
      * @see java.util.Map#size()
@@ -222,6 +225,10 @@
     public  int size() {
         return implementation.size();
     }
+
+    public int getSize() {
+        return size();
+    }
     public  boolean contains(Object key) {
         return implementation.containsKey(key);
     }


Index: CacheManager.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/cache/CacheManager.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- CacheManager.java   23 Jun 2008 12:45:35 -0000      1.27
+++ CacheManager.java   11 Jul 2008 12:46:44 -0000      1.28
@@ -19,12 +19,15 @@
 
 import java.util.concurrent.ConcurrentHashMap;
 
+import java.lang.management.*;
+import javax.management.*;
+
 
 /**
  * Cache manager manages the static methods of [EMAIL PROTECTED] Cache}. If 
you prefer you can call them on this in stead.
  *
  * @since MMBase-1.8
- * @version $Id: CacheManager.java,v 1.27 2008/06/23 12:45:35 michiel Exp $
+ * @version $Id: CacheManager.java,v 1.28 2008/07/11 12:46:44 michiel Exp $
  */
 public abstract class CacheManager {
 
@@ -96,6 +99,18 @@
     public static <K,V> Cache<K,V> putCache(Cache<K,V> cache) {
         Cache old = caches.put(cache.getName(), cache);
         configure(configReader, cache.getName());
+        Hashtable<String, String> props = new Hashtable<String, String>();
+        props.put("type", "CacheMBean");
+        props.put("mmb", 
org.mmbase.module.core.MMBase.getMMBase().getMachineName());
+        props.put("name", cache.getName());
+        try {
+            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+
+            ObjectName name = new ObjectName("org.mmbase.cache", props);
+            mbs.registerMBean(cache, name);
+        } catch (JMException jmo) {
+            log.warn("" + props + " " + jmo.getClass() + " " + 
jmo.getMessage());
+        }
         return old;
     }
 
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to