[jboss-cvs] JBossCache/src/org/jboss/cache/jmx ...
Manik Surtani
msurtani at jboss.com
Thu Jan 4 10:39:39 EST 2007
User: msurtani
Date: 07/01/04 10:39:39
Modified: src/org/jboss/cache/jmx CacheJmxWrapper.java
CacheMBean.java Cache.java
CacheLegacyJmxWrapper.java
Log:
Updated JMX interfaces
Revision Changes Path
1.11 +20 -44 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.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- CacheJmxWrapper.java 2 Jan 2007 18:26:05 -0000 1.10
+++ CacheJmxWrapper.java 4 Jan 2007 15:39:38 -0000 1.11
@@ -34,13 +34,11 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-public class CacheJmxWrapper
- implements CacheJmxWrapperMBean, MBeanRegistration
+public abstract class CacheJmxWrapper extends org.jboss.cache.jmx.Cache implements CacheJmxWrapperMBean, MBeanRegistration
{
private Log log = LogFactory.getLog(getClass().getName());
private boolean registerInterceptors = true;
- private CacheImpl tcpi;
private Configuration config;
private MBeanServer server;
private String cacheObjectName;
@@ -63,27 +61,24 @@
public Cache getCache()
{
- return tcpi;
- }
-
- public String printCacheDetails()
- {
- return tcpi == null ? null : tcpi.printDetails();
+ return cache;
}
public void create() throws Exception
{
- if (tcpi == null)
+ if (cache == null)
{
if (config == null)
+ {
throw new ConfigurationException("Must call setConfiguration() or setCache()before call to create()");
+ }
constructCache();
}
if (selfConstructed)
{
- tcpi.create();
+ cache.create();
}
registeredInterceptorsInCreate = registerInterceptors();
@@ -94,20 +89,24 @@
public void start() throws Exception
{
if (selfConstructed)
- tcpi.start();
+ {
+ cache.start();
+ }
}
public void stop()
{
if (selfConstructed)
- tcpi.stop();
+ {
+ cache.stop();
+ }
}
public void destroy()
{
if (selfConstructed)
{
- tcpi.destroy();
+ cache.destroy();
if (registeredInterceptorsInCreate)
{
@@ -154,7 +153,7 @@
{
log.debug("Registered in JMX under " + cacheObjectName);
- if (tcpi != null)
+ if (cache != null)
{
try
{
@@ -212,11 +211,13 @@
public void setCache(Cache cache)
{
if (created)
+ {
throw new IllegalStateException("Cannot set underlying cache after call to create()");
+ }
// FIXME -- the only reason we need to cast here is to support printCacheDetails
- this.tcpi = (CacheImpl) cache;
- this.config = (tcpi == null ? null : tcpi.getConfiguration());
+ this.cache = (CacheImpl) cache;
+ this.config = (cache == null ? null : cache.getConfiguration());
}
public String getCacheObjectName()
@@ -259,7 +260,7 @@
if (registerInterceptors && !interceptorsRegistered && server != null)
{
log.debug("Registering interceptors");
- JmxUtil.registerInterceptors(server, tcpi.getInterceptorChain(), cacheObjectName);
+ JmxUtil.registerInterceptors(server, cache.getInterceptorChain(), cacheObjectName);
interceptorsRegistered = true;
return true;
}
@@ -273,7 +274,7 @@
try
{
log.debug("Unreqistering interceptors");
- JmxUtil.unregisterInterceptors(server, tcpi.getInterceptorChain(), getCacheObjectName());
+ JmxUtil.unregisterInterceptors(server, cache.getInterceptorChain(), getCacheObjectName());
interceptorsRegistered = false;
}
catch (Exception e)
@@ -282,29 +283,4 @@
}
}
}
-
- // Disable NotificationBroadcaster for now
-// public void addNotificationListener(NotificationListener notificationListener, NotificationFilter notificationFilter, Object object) throws IllegalArgumentException
-// {
-// getCacheMgmtInterceptor().addNotificationListener(notificationListener, notificationFilter, object);
-// }
-//
-// public void removeNotificationListener(NotificationListener notificationListener) throws ListenerNotFoundException
-// {
-// getCacheMgmtInterceptor().removeNotificationListener(notificationListener);
-// }
-//
-// public MBeanNotificationInfo[] getNotificationInfo()
-// {
-// return getCacheMgmtInterceptor().getNotificationInfo();
-// }
-//
-// private CacheMgmtInterceptor getCacheMgmtInterceptor()
-// {
-// for (Interceptor i : tcpi.cache.getInterceptors())
-// {
-// if (i instanceof CacheMgmtInterceptor) return (CacheMgmtInterceptor) i;
-// }
-// throw new RuntimeException("Cache management interceptor not found");
-// }
}
1.9 +63 -3 JBossCache/src/org/jboss/cache/jmx/CacheMBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheMBean.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/jmx/CacheMBean.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- CacheMBean.java 3 Jan 2007 15:33:09 -0000 1.8
+++ CacheMBean.java 4 Jan 2007 15:39:38 -0000 1.9
@@ -10,9 +10,17 @@
import org.jboss.cache.config.Configuration;
/**
- * JMX interface to the {@link org.jboss.cache.Cache}
+ * JMX interface to the {@link org.jboss.cache.Cache}. Full access to the cache is not supported, only a certain
+ * set of operations are exposed via JMX:
+ * <p/>
+ * <ol>
+ * <li> Lifecycle methods - create, start, stop, destroy</li>
+ * <li> Configuration (read-only) getter - which retrieves a String (or formatted HTML for web based JMX consoles) representation of the configuration</li>
+ * <li> Setters for a specific subset of config elements which may be changed at runtime</li>
+ * <li> Cache information methods (numNodes, numAttributes, lockInfo, printDetails) which print as Strings or as formatted HTML (for web based JMX consoles)</li>
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ * @since 2.0.0
*/
public interface CacheMBean extends LifeCycle
{
@@ -22,9 +30,61 @@
Cache getCache();
/**
- * Retrieves an immutable configuration
+ * @return an immutable configuration
*/
Configuration getConfiguration();
- String printCacheDetails();
+ /**
+ * @return a string based representation of the configuration
+ */
+ String getConfigurationAsString();
+
+ /**
+ * @return an HTML formatted string based representation of the configuration
+ */
+ String getConfigurationAsHtmlString();
+
+ /**
+ * @return details of nodes in the cache
+ */
+ String getCacheDetails();
+
+ /**
+ * @return details of nodes in the cache, formatted as HTML
+ */
+ String getCacheDetailsAsHtml();
+
+ /**
+ * @return number of nodes in the cache
+ */
+ int getNumberOfNodes();
+
+ /**
+ * @return number of attributes in the cache
+ */
+ int getNumberOfAttributes();
+
+ /**
+ * @return information on the state of node locks
+ */
+ String getLockInfo();
+
+ /**
+ * @return information on the state of node locks, formatted as HTML
+ */
+ String getLockInfoAsHtml();
+
+ // ========= These are (primitive) configuration elements that may be changed at runtime. ===========
+
+ void setReplQueueMaxElements(int i);
+
+ void setReplQueueInterval(long l);
+
+ void setLockAcquisitionTimeout(long l);
+
+ void setSyncReplTimeout(long l);
+
+ void setSyncCommitPhase(boolean b);
+
+ void setSyncRollbackPhase(boolean b);
}
1.7 +43 -19 JBossCache/src/org/jboss/cache/jmx/Cache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Cache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/jmx/Cache.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- Cache.java 30 Dec 2006 17:49:58 -0000 1.6
+++ Cache.java 4 Jan 2007 15:39:38 -0000 1.7
@@ -2,7 +2,6 @@
import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
-import org.jboss.cache.config.Configuration;
import org.jboss.cache.interceptors.CacheMgmtInterceptor;
import org.jboss.cache.interceptors.Interceptor;
@@ -17,48 +16,57 @@
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
*/
-public class Cache implements CacheMBean, NotificationBroadcaster
+public abstract class Cache implements CacheMBean, NotificationBroadcaster
{
- private CacheImpl tcpi;
+ protected CacheImpl cache;
+
+ public Cache()
+ {
+ }
public Cache(CacheSPI cacheSPI)
{
- tcpi = (CacheImpl) cacheSPI;
+ cache = (CacheImpl) cacheSPI;
+ }
+
+ public String getConfigurationAsString()
+ {
+ return cache == null ? "Cache is null" : cache.getConfiguration().toString();
}
- public org.jboss.cache.Cache getCache()
+ public String getConfigurationAsHtmlString()
{
- return tcpi;
+ return cache == null ? "Cache is null" : formatHtml(cache.getConfiguration().toString());
}
- public void start() throws Exception
+ public String getCacheDetails()
{
- tcpi.start();
+ return cache == null ? "Cache is null" : cache.printDetails();
}
- public void stop()
+ public String getCacheDetailsAsHtml()
{
- tcpi.stop();
+ return cache == null ? "Cache is null" : formatHtml(cache.printDetails());
}
- public void create() throws Exception
+ public int getNumberOfNodes()
{
- tcpi.create();
+ return cache == null ? -1 : cache.getNumberOfNodes();
}
- public void destroy()
+ public int getNumberOfAttributes()
{
- tcpi.destroy();
+ return cache == null ? -1 : cache.getNumberOfAttributes();
}
- public Configuration getConfiguration()
+ public String getLockInfo()
{
- return tcpi.getConfiguration();
+ return cache == null ? "Cache is null" : cache.printLockInfo();
}
- public String printCacheDetails()
+ public String getLockInfoAsHtml()
{
- return tcpi.printDetails();
+ return cache == null ? "Cache is null" : formatHtml(cache.printLockInfo());
}
public void addNotificationListener(NotificationListener notificationListener, NotificationFilter notificationFilter, Object object) throws IllegalArgumentException
@@ -78,10 +86,26 @@
private CacheMgmtInterceptor getCacheMgmtInterceptor()
{
- for (Interceptor i : tcpi.getInterceptors())
+ for (Interceptor i : cache.getInterceptors())
{
if (i instanceof CacheMgmtInterceptor) return (CacheMgmtInterceptor) i;
}
throw new RuntimeException("Cache management interceptor not found");
}
+
+ /**
+ * Formats a given String for display as an HTML snippet.
+ *
+ * @param s string to format
+ * @return formatted string
+ */
+ protected String formatHtml(String s)
+ {
+ s = s.replaceAll("\r\n", "<br />");
+ s = s.replaceAll("\r", "<br />");
+ s = s.replaceAll("\n", "<br />");
+ s = s.replaceAll("\t", " ");
+ s = s.replaceAll(" ", " ");
+ return s;
+ }
}
1.3 +2 -3 JBossCache/src/org/jboss/cache/jmx/CacheLegacyJmxWrapper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLegacyJmxWrapper.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/jmx/CacheLegacyJmxWrapper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- CacheLegacyJmxWrapper.java 3 Jan 2007 15:33:09 -0000 1.2
+++ CacheLegacyJmxWrapper.java 4 Jan 2007 15:39:38 -0000 1.3
@@ -37,10 +37,9 @@
* configuration of the cache using the JBoss AS 4.x JMX microkernel.
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
-public class CacheLegacyJmxWrapper
- extends CacheJmxWrapper implements CacheLegacyJmxWrapperMBean
+public class CacheLegacyJmxWrapper extends CacheJmxWrapper implements CacheLegacyJmxWrapperMBean
{
private Element buddyReplConfig;
private Element evictionConfig;
More information about the jboss-cvs-commits
mailing list