You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@apache.org on 2001/11/12 05:52:59 UTC
cvs commit: jakarta-slide/src/wrappers/jmx SlideJMX.java mbeans-descriptors.xml MBeanUtils.java
remm 01/11/11 20:52:59
Modified: src/wrappers/catalina SlideServerListener.java
src/wrappers/jmx mbeans-descriptors.xml
Added: src/wrappers/jmx SlideJMX.java
Removed: src/wrappers/jmx MBeanUtils.java
Log:
- Rename the MBeanUtils class.
- Change a bit the API.
- Fix some limitiations in the createMBean method (the algorithm will look at the superclass
to try to find an appropriate model bean).
- Add a few attributes and operations to the MBean descriptor file.
Revision Changes Path
1.7 +20 -9 jakarta-slide/src/wrappers/catalina/SlideServerListener.java
Index: SlideServerListener.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideServerListener.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SlideServerListener.java 2001/11/11 20:11:30 1.6
+++ SlideServerListener.java 2001/11/12 04:52:59 1.7
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideServerListener.java,v 1.6 2001/11/11 20:11:30 remm Exp $
- * $Revision: 1.6 $
- * $Date: 2001/11/11 20:11:30 $
+ * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideServerListener.java,v 1.7 2001/11/12 04:52:59 remm Exp $
+ * $Revision: 1.7 $
+ * $Date: 2001/11/12 04:52:59 $
*
* ====================================================================
*
@@ -99,14 +99,14 @@
import org.apache.slide.util.conf.Populate;
import org.apache.slide.util.logger.SimpleLogger;
-import wrappers.jmx.MBeanUtils;
+import wrappers.jmx.SlideJMX;
/**
* Server listener responsible for setting up the Slide domain.
*
* @author Remy Maucherat
- * @version $Revision: 1.6 $ $Date: 2001/11/11 20:11:30 $
+ * @version $Revision: 1.7 $ $Date: 2001/11/12 04:52:59 $
*/
public class SlideServerListener
implements LifecycleListener {
@@ -150,14 +150,14 @@
logger.setLoggerLevel(6);
domain.setLogger(logger);
+ slideJMXWrapper = new SlideJMX();
+ slideJMXWrapper.setDomain(domain);
+
System.out.println("Starting Slide");
initializeDomain();
domain.start();
System.out.println("Slide started");
- // Register the domain as a MBean
- MBeanUtils.createMBean(domain);
-
} else if (event.getType() == Lifecycle.STOP_EVENT) {
System.out.println("Stopping Slide");
@@ -165,7 +165,7 @@
System.out.println("Slide stopped");
// Unregister the domain as a MBean
- MBeanUtils.destroyMBean(domain);
+ //MBeanUtils.destroyMBean(domain);
}
@@ -209,6 +209,12 @@
protected int logLevel = 6;
+ /**
+ * JMX wrapper.
+ */
+ protected SlideJMX slideJMXWrapper = null;
+
+
// ------------------------------------------------------------- Properties
@@ -355,6 +361,11 @@
domain.addNamespace(name, nsLogger, definition,
configuration, baseData);
+ try {
+ slideJMXWrapper.addNamespace(name);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
1.2 +99 -2 jakarta-slide/src/wrappers/jmx/mbeans-descriptors.xml
Index: mbeans-descriptors.xml
===================================================================
RCS file: /home/cvs/jakarta-slide/src/wrappers/jmx/mbeans-descriptors.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- mbeans-descriptors.xml 2001/11/11 20:21:10 1.1
+++ mbeans-descriptors.xml 2001/11/12 04:52:59 1.2
@@ -6,21 +6,96 @@
<!--
Descriptions of JMX MBeans for Catalina
- $Id: mbeans-descriptors.xml,v 1.1 2001/11/11 20:21:10 remm Exp $
+ $Id: mbeans-descriptors.xml,v 1.2 2001/11/12 04:52:59 remm Exp $
-->
<mbeans-descriptors>
- <mbean name="EmbeddedDomain"
+ <mbean name="Domain"
className="wrappers.jmx.DomainMBean"
description="Slide Domain"
domain="Slide"
group="Core"
type="org.apache.slide.common.EmbeddedDomain">
+ <attribute name="name"
+ description="The name of the domain"
+ type="java.lang.String"/>
+
+ <attribute name="defaultNamespace"
+ description="The name of the default namespace for the domain"
+ type="java.lang.String"/>
+
+ <attribute name="logger"
+ description="The logger for the domain"
+ type="org.apache.slide.util.logger.Logger"/>
+
<constructor name="EmbeddedDomain"/>
+ <operation name="getNamespace"
+ description="Return a namespace"
+ impact="INFO"
+ returnType="org.apache.slide.common.Namespace">
+ <parameter name="name"
+ description="Name of the namespace"
+ type="java.lang.String"/>
+ </operation>
+
+ <operation name="getNamespaceToken"
+ description="Return a namespace token which gives access to the specified namespace"
+ impact="INFO"
+ returnType="org.apache.slide.common.NamespaceAccessToken">
+ <parameter name="name"
+ description="Name of the namespace to be accessed"
+ type="java.lang.String"/>
+ </operation>
+
+ <operation name="enumerateNamespaces"
+ description="Return the list of namespaces in this domain"
+ impact="INFO"
+ returnType="java.util.Enumeration"/>
+
+ <operation name="addNamespace"
+ description="Add a namespace"
+ impact="ACTION"
+ returnType="org.apache.slide.common.Namespace">
+ <parameter name="name"
+ description="Name of the namespace to be added"
+ type="java.lang.String"/>
+ <parameter name="logger"
+ description="Namespace logger"
+ type="org.apache.slide.util.logger.Logger"/>
+ <parameter name="definition"
+ description="Namespace definition"
+ type="org.apache.slide.util.conf.Configuration"/>
+ <parameter name="configuration"
+ description="Namespace configuration"
+ type="org.apache.slide.util.conf.Configuration"/>
+ <parameter name="baseData"
+ description="Namespace bootstrap data"
+ type="org.apache.slide.util.conf.Configuration"/>
+ </operation>
+
+ <operation name="removeNamespace"
+ description="Remove a namespace"
+ impact="ACTION"
+ returnType="org.apache.slide.common.Namespace">
+ <parameter name="name"
+ description="Name of the namespace to be removed"
+ type="java.lang.String"/>
+ </operation>
+
+ <operation name="start"
+ description="Start domain"
+ impact="ACTION"
+ returnType="void"/>
+
+ <operation name="stop"
+ description="Stop domain"
+ impact="ACTION"
+ returnType="void"/>
+
</mbean>
@@ -30,6 +105,28 @@
domain="Slide"
group="Core"
type="org.apache.slide.common.Namespace">
+
+ <attribute name="name"
+ description="The name of the namespace"
+ type="java.lang.String"/>
+
+ <attribute name="config"
+ description="Namespace configuration"
+ type="org.apache.slide.common.NamespaceConfig"
+ writeable="false"/>
+
+ <attribute name="logger"
+ description="The logger for the namespace"
+ type="org.apache.slide.util.logger.Logger"/>
+
+ <attribute name="transactionManager"
+ description="The transaction manager of the namespace"
+ type="javax.transaction.TransactionManager"
+ writeable="false"/>
+
+ <attribute name="applicationLogger"
+ description="The application logger for the namespace"
+ type="org.apache.slide.util.logger.Logger"/>
<constructor name="Namespace"/>
1.1 jakarta-slide/src/wrappers/jmx/SlideJMX.java
Index: SlideJMX.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/wrappers/jmx/SlideJMX.java,v 1.1 2001/11/12 04:52:59 remm Exp $
* $Revision: 1.1 $
* $Date: 2001/11/12 04:52:59 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package wrappers.jmx;
import java.io.InputStream;
import java.net.URL;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.OperationsException;
import javax.management.modelmbean.InvalidTargetObjectTypeException;
import javax.management.modelmbean.ModelMBean;
import org.apache.commons.modeler.ManagedBean;
import org.apache.commons.modeler.Registry;
import org.apache.slide.common.EmbeddedDomain;
import org.apache.slide.common.Namespace;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.NamespaceConfig;
/**
* Public utility methods in support of the server side MBeans implementation.
*
* @author Remy Maucherat
* @author Craig R. McClanahan
* @author Amy Roh
* @version $Revision: 1.1 $ $Date: 2001/11/12 04:52:59 $
*/
public class SlideJMX {
// ----------------------------------------------------------- Constructors
/**
* Construct Slide JMX wrapper.
*/
public SlideJMX() {
}
// ------------------------------------------------------- Static Variables
/**
* The set of exceptions to the normal rules used by
* <code>createManagedBean()</code>. The first element of each pair
* is a class name, and the second element is the managed bean name.
*/
private static String exceptions[][] = {
{ "className", "finalName" },
{ "org.apache.slide.common.EmbeddedDomain", "Domain" }
};
/**
* The configuration information registry for our managed beans.
*/
private static Registry registry = createRegistry();
/**
* The <code>MBeanServer</code> for this application.
*/
private static MBeanServer mserver = createServer();
/**
* Associated Slide domain.
*/
private EmbeddedDomain domain = null;
// --------------------------------------------------------- Public Methods
/**
* Generate MBeans for the specified domain.
*/
public void setDomain(EmbeddedDomain domain)
throws Exception {
this.domain = domain;
createMBean(domain);
}
/**
* Generate MBeans for the specified namespace.
*/
public void addNamespace(String name)
throws Exception {
Namespace namespace = domain.getNamespace(name);
if (namespace != null) {
createMBean(namespace);
createMBean(namespace.getConfig());
}
}
// --------------------------------------------------------- Static Methods
/**
* Create and return the name of the <code>ManagedBean</code> that
* corresponds to this Catalina component.
*
* @param component The component for which to create a name
*/
public static String createManagedName(Object component) {
return createManagedName(component.getClass());
}
/**
* Create and return the name of the <code>ManagedBean</code> that
* corresponds to this Catalina component.
*
* @param component The component class name for which to create a name
*/
public static String createManagedName(Class clazz) {
// Deal with exceptions to the standard rule
String className = clazz.getName();
for (int i = 0; i < exceptions.length; i++) {
if (className.equals(exceptions[i][0]))
return (exceptions[i][1]);
}
// Perform the standard transformation
int period = className.lastIndexOf('.');
if (period >= 0)
className = className.substring(period + 1);
return (className);
}
/**
* Find the managed bean associated with this object.
*
* @param object The object to be managed
*/
public static ManagedBean findManagedBean(Object object)
throws Exception {
ManagedBean result = null;
String mname = null;
Class clazz = object.getClass();
while ((clazz != null) && (result == null)) {
mname = createManagedName(clazz);
result = registry.findManagedBean(mname);
if (result == null) {
Class[] interfaces = clazz.getInterfaces();
for (int i = 0; (i < interfaces.length)
&& (result == null); i++) {
mname = createManagedName(interfaces[i]);
result = registry.findManagedBean(mname);
}
}
if (result == null)
clazz = clazz.getSuperclass();
}
return result;
}
/**
* Create, register, and return an MBean for this object.
*
* @param object The object to be managed
*
* @exception Exception if an MBean cannot be created or registered
*/
public static ModelMBean createMBean(Object object)
throws Exception {
String mname = createManagedName(object);
ManagedBean managed = registry.findManagedBean(mname);
if (managed == null)
managed = findManagedBean(object);
if (managed == null)
return null;
String domain = managed.getDomain();
if (domain == null)
domain = mserver.getDefaultDomain();
ModelMBean mbean = managed.createMBean(object);
ObjectName oname = createObjectName(domain, mname, object);
mserver.registerMBean(mbean, oname);
return (mbean);
}
/**
* Create an <code>ObjectName</code> for this object.
*
* @param domain Domain in which this name is to be created
* @param mname Managed name of the object
* @param object Object to be named
*
* @exception MalformedObjectNameException if a name cannot be created
*/
public static ObjectName createObjectName
(String domain, String mname, Object object)
throws MalformedObjectNameException {
return new ObjectName(domain + ":type=" + mname + ",name="
+ object.toString());
}
/**
* Create and configure (if necessary) and return the registry of
* managed object descriptions.
*/
public synchronized static Registry createRegistry() {
if (registry == null) {
try {
URL url = MBeanUtils.class.getResource
("/wrappers/jmx/mbeans-descriptors.xml");
InputStream stream = url.openStream();
Registry.loadRegistry(stream);
stream.close();
registry = Registry.getRegistry();
} catch (Throwable t) {
t.printStackTrace(System.out);
}
}
return (registry);
}
/**
* Create and configure (if necessary) and return the
* <code>MBeanServer</code> with which we will be
* registering our <code>ModelMBean</code> implementations.
*/
public synchronized static MBeanServer createServer() {
if (mserver == null) {
try {
mserver = Registry.getServer();
} catch (Throwable t) {
t.printStackTrace(System.out);
}
}
return (mserver);
}
/**
* Deregister the MBean for the specified object.
*
* @param object The objectr to be managed
*
* @exception Exception if an MBean cannot be deregistered
*/
public static void destroyMBean(Object object)
throws Exception {
String mname = createManagedName(object);
ManagedBean managed = registry.findManagedBean(mname);
String domain = managed.getDomain();
if (domain == null)
domain = mserver.getDefaultDomain();
ObjectName oname = createObjectName(domain, mname, object);
mserver.unregisterMBean(oname);
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>