[jboss-cvs] JBossCache/src/org/jboss/cache/jmx ...
Manik Surtani
msurtani at jboss.com
Thu Sep 7 09:52:28 EDT 2006
User: msurtani
Date: 06/09/07 09:52:28
Modified: src/org/jboss/cache/jmx Cache.java CacheMBean.java
Added: src/org/jboss/cache/jmx JmxUtil.java LifeCycle.java
Log:
cleaned up jmx interfaces, fixed tx and gtx allocation problems
Revision Changes Path
1.3 +0 -0 JBossCache/src/org/jboss/cache/jmx/Cache.java
(In the diff below, changes in quantity of whitespace are not shown.)
1.5 +1 -9 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.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- CacheMBean.java 6 Sep 2006 14:45:41 -0000 1.4
+++ CacheMBean.java 7 Sep 2006 13:52:28 -0000 1.5
@@ -14,21 +14,13 @@
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
-public interface CacheMBean
+public interface CacheMBean extends LifeCycle
{
/**
* Retrieves a reference to the underlying {@link Cache}
*/
Cache getCache();
- void start() throws Exception;
-
- void stop();
-
- void create() throws Exception;
-
- void destroy();
-
/**
* Retrieves an immutable configuration
*/
1.1 date: 2006/09/07 13:52:28; author: msurtani; state: Exp;JBossCache/src/org/jboss/cache/jmx/JmxUtil.java
Index: JmxUtil.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.cache.jmx;
import org.jboss.cache.TreeCache;
import org.jboss.cache.interceptors.Interceptor;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import java.util.ArrayList;
import java.util.List;
/**
* Various JMX related utilities
*
* @author Jerry Gauthier
* @author Manik Surtani
* @version $Id: JmxUtil.java,v 1.1 2006/09/07 13:52:28 msurtani Exp $
*/
public class JmxUtil
{
public static final String MBEAN_CLASS_SUFFIX = "MBean";
public static final String MBEAN_KEY = ",treecache-interceptor=";
public static final String PREFIX = "jboss.cache:service=";
private static final String JBOSS_SERVER_DOMAIN = "jboss";
/*
* Register the associated mbeans for cache interceptors
*
* @param server the mbean server with which the mbeans should be registered
* @param cache the cache having the set of interceptors to be registered
* @param registerCache whether the cache itself should be registered
*/
public static void registerInterceptors(MBeanServer server, TreeCache cache, boolean registerCache)
throws Exception
{
if (server == null || cache == null)
return;
List interceptors = cache.getInterceptors();
Interceptor interceptor = null;
// get the cache's registration name
String tmpName = cache.getConfiguration().getServiceName();
if (tmpName == null)
{
tmpName = PREFIX + cache.getConfiguration().getClusterName();
if (cache.getConfiguration().getClusterName() == null)
tmpName = PREFIX + cache.getClass().getName() + System.currentTimeMillis();
}
// register the cache
if (registerCache)
{
ObjectName tmpObj = new ObjectName(tmpName);
if (!server.isRegistered(tmpObj))
server.registerMBean(cache.getCacheMBeanInterface(), tmpObj);
}
for (int i = 0; i < interceptors.size(); i++)
{
interceptor = (Interceptor) interceptors.get(i);
boolean mbeanExists = true;
try
{
// the mbean for interceptor AbcInterceptor will be named AbcInterceptorMBean
Class.forName(interceptor.getClass().getName() + MBEAN_CLASS_SUFFIX);
}
catch (Throwable e)
{
// if the class can't be instantiated, no mbean is available
mbeanExists = false;
}
// for JDK 1.4, must parse name and remove package prefix
// for JDK 1.5, can use getSimpleName() to establish class name without package prefix
String className = interceptor.getClass().getName();
String serviceName = tmpName + MBEAN_KEY + className.substring(className.lastIndexOf('.') + 1);
ObjectName objName = new ObjectName(serviceName);
if (!server.isRegistered(objName))
{
if (mbeanExists)
// register associated interceptor mbean
server.registerMBean(interceptor, objName);
//else
// register dummy interceptor mbean
// server.registerMBean(new BaseInterceptor(), objName);
}
}
}
/*
* Unregister the associated mbeans for cache interceptors
*
* @param server the mbean server for which the mbeans should be unregistered
* @param cache the cache having the set of interceptors to be unregistered
* @param unregisterCache whether the cache itself should be unregistered
*/
public static void unregisterInterceptors(MBeanServer server, TreeCache cache, boolean unregisterCache)
throws Exception
{
if (server == null || cache == null)
return;
List interceptors = cache.getInterceptors();
Interceptor interceptor = null;
// get the cache's registration name
String tmpName = cache.getConfiguration().getServiceName();
if (tmpName == null)
{
tmpName = PREFIX + cache.getConfiguration().getClusterName();
if (cache.getConfiguration().getClusterName() == null)
tmpName = PREFIX + cache.getClass().getName() + System.currentTimeMillis();
}
for (int i = 0; i < interceptors.size(); i++)
{
interceptor = (Interceptor) interceptors.get(i);
// for JDK 1.4, must parse name and remove package prefix
// for JDK 1.5, can use getSimpleName() to establish class name without package prefix
String className = interceptor.getClass().getName();
String serviceName = tmpName + MBEAN_KEY + className.substring(className.lastIndexOf('.') + 1);
ObjectName objName = new ObjectName(serviceName);
if (server.isRegistered(objName))
server.unregisterMBean(objName);
}
// unregister the cache itself
if (unregisterCache)
{
ObjectName tmpObj = new ObjectName(tmpName);
if (server.isRegistered(tmpObj))
server.unregisterMBean(tmpObj);
}
}
public static MBeanServer getMBeanServer()
{
ArrayList servers = MBeanServerFactory.findMBeanServer(null);
if (servers == null || servers.size() == 0)
{
return null;
}
// return 'jboss' server if available
for (int i = 0; i < servers.size(); i++)
{
MBeanServer server = (MBeanServer) servers.get(i);
if (server.getDefaultDomain().equalsIgnoreCase(JBOSS_SERVER_DOMAIN))
{
return server;
}
}
// return first available server
return (MBeanServer) servers.get(0);
}
}
1.1 date: 2006/09/07 13:52:28; author: msurtani; state: Exp;JBossCache/src/org/jboss/cache/jmx/LifeCycle.java
Index: LifeCycle.java
===================================================================
package org.jboss.cache.jmx;
/**
* Basic lifecycle methods
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
*/
public interface LifeCycle
{
void create() throws Exception;
void start() throws Exception;
void stop();
void destroy();
}
More information about the jboss-cvs-commits
mailing list