amyroh 2002/06/06 15:36:47
Modified: catalina/src/share/org/apache/catalina/mbeans
MBeanUtils.java StandardContextMBean.java
mbeans-descriptors.xml
Log:
Add MBean support for JNDI resource and resource link under Context.
Revision Changes Path
1.38 +82 -5
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java
Index: MBeanUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- MBeanUtils.java 13 May 2002 18:25:47 -0000 1.37
+++ MBeanUtils.java 6 Jun 2002 22:36:47 -0000 1.38
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
1.37 2002/05/13 18:25:47 amyroh Exp $
- * $Revision: 1.37 $
- * $Date: 2002/05/13 18:25:47 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
1.38 2002/06/06 22:36:47 amyroh Exp $
+ * $Revision: 1.38 $
+ * $Date: 2002/06/06 22:36:47 $
*
* ====================================================================
*
@@ -102,6 +102,7 @@
import org.apache.catalina.core.StandardService;
import org.apache.catalina.deploy.ContextEnvironment;
import org.apache.catalina.deploy.ContextResource;
+import org.apache.catalina.deploy.ContextResourceLink;
import org.apache.catalina.deploy.NamingResources;
import org.apache.catalina.deploy.ResourceParams;
import org.apache.catalina.valves.ValveBase;
@@ -115,7 +116,7 @@
*
* @author Craig R. McClanahan
* @author Amy Roh
- * @version $Revision: 1.37 $ $Date: 2002/05/13 18:25:47 $
+ * @version $Revision: 1.38 $ $Date: 2002/06/06 22:36:47 $
*/
public class MBeanUtils {
@@ -317,6 +318,34 @@
return (mbean);
}
+
+
+ /**
+ * Create, register, and return an MBean for this
+ * <code>ContextResourceLink</code> object.
+ *
+ * @param resourceLink The ContextResourceLink to be managed
+ *
+ * @exception Exception if an MBean cannot be created or registered
+ */
+ public static ModelMBean createMBean(ContextResourceLink resourceLink)
+ throws Exception {
+
+ String mname = createManagedName(resourceLink);
+ ManagedBean managed = registry.findManagedBean(mname);
+ if (managed == null) {
+ Exception e = new Exception("ManagedBean is not found with "+mname);
+ throw new MBeanException(e);
+ }
+ String domain = managed.getDomain();
+ if (domain == null)
+ domain = mserver.getDefaultDomain();
+ ModelMBean mbean = managed.createMBean(resourceLink);
+ ObjectName oname = createObjectName(domain, resourceLink);
+ mserver.registerMBean(mbean, oname);
+ return (mbean);
+
+ }
/**
@@ -901,7 +930,7 @@
/**
* Create an <code>ObjectName</code> for this
- * <code>Service</code> object.
+ * <code>ContextResource</code> object.
*
* @param domain Domain in which this name is to be created
* @param resource The ContextResource to be named
@@ -920,6 +949,29 @@
return (name);
}
+
+
+ /**
+ * Create an <code>ObjectName</code> for this
+ * <code>ContextResourceLink</code> object.
+ *
+ * @param domain Domain in which this name is to be created
+ * @param resourceLink The ContextResourceLink to be named
+ *
+ * @exception MalformedObjectNameException if a name cannot be created
+ */
+ public static ObjectName createObjectName(String domain,
+ ContextResourceLink resourceLink)
+ throws MalformedObjectNameException {
+
+ ObjectName name = null;
+ String encodedResourceLinkName = encodeStr(resourceLink.getName());
+ name = new ObjectName(domain + ":type=ResourceLink,class=" +
+ resourceLink.getType()+",name=" +
+ encodedResourceLinkName);
+ return (name);
+
+ }
/**
@@ -1535,6 +1587,31 @@
mserver.unregisterMBean(oname);
}
+
+
+ /**
+ * Deregister the MBean for this
+ * <code>ContextResourceLink</code> object.
+ *
+ * @param resourceLink The ContextResourceLink to be managed
+ *
+ * @exception Exception if an MBean cannot be deregistered
+ */
+ public static void destroyMBean(ContextResourceLink resourceLink)
+ throws Exception {
+
+ String mname = createManagedName(resourceLink);
+ ManagedBean managed = registry.findManagedBean(mname);
+ if (managed == null) {
+ return;
+ }
+ String domain = managed.getDomain();
+ if (domain == null)
+ domain = mserver.getDefaultDomain();
+ ObjectName oname = createObjectName(domain, resourceLink);
+ mserver.unregisterMBean(oname);
+
+ }
/**
1.6 +262 -16
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardContextMBean.java
Index: StandardContextMBean.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardContextMBean.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StandardContextMBean.java 8 Mar 2002 22:01:07 -0000 1.5
+++ StandardContextMBean.java 6 Jun 2002 22:36:47 -0000 1.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardContextMBean.java,v
1.5 2002/03/08 22:01:07 amyroh Exp $
- * $Revision: 1.5 $
- * $Date: 2002/03/08 22:01:07 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardContextMBean.java,v
1.6 2002/06/06 22:36:47 amyroh Exp $
+ * $Revision: 1.6 $
+ * $Date: 2002/06/06 22:36:47 $
*
* ====================================================================
*
@@ -63,34 +63,32 @@
package org.apache.catalina.mbeans;
-
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import javax.management.MalformedObjectNameException;
import javax.management.MBeanException;
-import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.RuntimeOperationsException;
-import org.apache.catalina.Loader;
-import org.apache.catalina.Logger;
-import org.apache.catalina.Manager;
-import org.apache.catalina.Realm;
-import org.apache.catalina.Valve;
import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.deploy.ContextEnvironment;
+import org.apache.catalina.deploy.ContextResource;
+import org.apache.catalina.deploy.ContextResourceLink;
+import org.apache.catalina.deploy.NamingResources;
+import org.apache.catalina.deploy.ResourceParams;
import org.apache.commons.modeler.BaseModelMBean;
-
+import org.apache.commons.modeler.ManagedBean;
+import org.apache.commons.modeler.Registry;
/**
* <p>A <strong>ModelMBean</strong> implementation for the
* <code>org.apache.catalina.core.StandardContext</code> component.</p>
*
* @author Amy Roh
- * @version $Revision: 1.5 $ $Date: 2002/03/08 22:01:07 $
+ * @version $Revision: 1.6 $ $Date: 2002/06/06 22:36:47 $
*/
public class StandardContextMBean extends BaseModelMBean {
- /**
- * The <code>MBeanServer</code> for this application.
- */
- private static MBeanServer mserver = MBeanUtils.createServer();
// ----------------------------------------------------------- Constructors
@@ -110,13 +108,261 @@
super();
}
+
+
+ // ----------------------------------------------------- Instance Variables
+
+
+ /**
+ * The configuration information registry for our managed beans.
+ */
+ protected Registry registry = MBeanUtils.createRegistry();
+ /**
+ * The <code>ManagedBean</code> information describing this MBean.
+ */
+ protected ManagedBean managed =
+ registry.findManagedBean("StandardContext");
+
// ------------------------------------------------------------- Attributes
+
+ /**
+ * Return the naming resources associated with this web application.
+ */
+ private NamingResources getNamingResources() {
+
+ return ((StandardContext)this.resource).getNamingResources();
+
+ }
+
+
+ /**
+ * Return the MBean Names of the set of defined environment entries for
+ * this web application
+ */
+ public String[] getEnvironments() {
+ ContextEnvironment[] envs = getNamingResources().findEnvironments();
+ ArrayList results = new ArrayList();
+ for (int i = 0; i < envs.length; i++) {
+ try {
+ ObjectName oname =
+ MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
+ results.add(oname.toString());
+ } catch (MalformedObjectNameException e) {
+ throw new IllegalArgumentException
+ ("Cannot create object name for environment " + envs[i]);
+ }
+ }
+ return ((String[]) results.toArray(new String[results.size()]));
+
+ }
+
+
+ /**
+ * Return the MBean Names of all the defined resource references for this
+ * application.
+ */
+ public String[] getResources() {
+
+ ContextResource[] resources = getNamingResources().findResources();
+ ArrayList results = new ArrayList();
+ for (int i = 0; i < resources.length; i++) {
+ try {
+ ObjectName oname =
+ MBeanUtils.createObjectName(managed.getDomain(), resources[i]);
+ results.add(oname.toString());
+ } catch (MalformedObjectNameException e) {
+ throw new IllegalArgumentException
+ ("Cannot create object name for resource " + resources[i]);
+ }
+ }
+ return ((String[]) results.toArray(new String[results.size()]));
+
+ }
+
+
+ /**
+ * Return the MBean Names of all the defined resource links for this
+ * application
+ */
+ public String[] getResourceLinks() {
+
+ ContextResourceLink[] links = getNamingResources().findResourceLinks();
+ ArrayList results = new ArrayList();
+ for (int i = 0; i < links.length; i++) {
+ try {
+ ObjectName oname =
+ MBeanUtils.createObjectName(managed.getDomain(), links[i]);
+ results.add(oname.toString());
+ } catch (MalformedObjectNameException e) {
+ throw new IllegalArgumentException
+ ("Cannot create object name for resource " + links[i]);
+ }
+ }
+ return ((String[]) results.toArray(new String[results.size()]));
+ }
// ------------------------------------------------------------- Operations
+
+ /**
+ * Add an environment entry for this web application.
+ *
+ * @param envName New environment entry name
+ */
+ public String addEnvironment(String envName, String type)
+ throws MalformedObjectNameException {
+
+ NamingResources nresources = getNamingResources();
+ if (nresources == null) {
+ return null;
+ }
+ ContextEnvironment env = nresources.findEnvironment(envName);
+ if (env != null) {
+ throw new IllegalArgumentException
+ ("Invalid environment name - already exists '" + envName + "'");
+ }
+ env = new ContextEnvironment();
+ env.setName(envName);
+ env.setType(type);
+ nresources.addEnvironment(env);
+
+ // Return the corresponding MBean name
+ ManagedBean managed = registry.findManagedBean("ContextEnvironment");
+ ObjectName oname =
+ MBeanUtils.createObjectName(managed.getDomain(), env);
+ return (oname.toString());
+
+ }
+
+
+ /**
+ * Add a resource reference for this web application.
+ *
+ * @param resourceName New resource reference name
+ */
+ public String addResource(String resourceName, String type)
+ throws MalformedObjectNameException {
+
+ NamingResources nresources = getNamingResources();
+ if (nresources == null) {
+ return null;
+ }
+ ContextResource resource = nresources.findResource(resourceName);
+ if (resource != null) {
+ throw new IllegalArgumentException
+ ("Invalid resource name - already exists'" + resourceName + "'");
+ }
+ resource = new ContextResource();
+ resource.setName(resourceName);
+ resource.setType(type);
+ nresources.addResource(resource);
+
+ // Return the corresponding MBean name
+ ManagedBean managed = registry.findManagedBean("ContextResource");
+ ObjectName oname =
+ MBeanUtils.createObjectName(managed.getDomain(), resource);
+ return (oname.toString());
+ }
+
+
+ /**
+ * Add a resource link for this web application.
+ *
+ * @param resourceLinkName New resource link name
+ */
+ public String addResourceLink(String resourceLinkName, String global,
+ String name, String type) throws MalformedObjectNameException {
+
+ NamingResources nresources = getNamingResources();
+ if (nresources == null) {
+ return null;
+ }
+ ContextResourceLink resourceLink =
+ nresources.findResourceLink(resourceLinkName);
+ if (resourceLink != null) {
+ throw new IllegalArgumentException
+ ("Invalid resource link name - already exists'" +
+ resourceLinkName + "'");
+ }
+ resourceLink = new ContextResourceLink();
+ resourceLink.setGlobal(global);
+ resourceLink.setName(resourceLinkName);
+ resourceLink.setType(type);
+ nresources.addResourceLink(resourceLink);
+
+ // Return the corresponding MBean name
+ ManagedBean managed = registry.findManagedBean("ContextResourceLink");
+ ObjectName oname =
+ MBeanUtils.createObjectName(managed.getDomain(), resourceLink);
+ return (oname.toString());
+ }
+
+
+ /**
+ * Remove any environment entry with the specified name.
+ *
+ * @param name Name of the environment entry to remove
+ */
+ public void removeEnvironment(String envName) {
+
+ NamingResources nresources = getNamingResources();
+ if (nresources == null) {
+ return;
+ }
+ ContextEnvironment env = nresources.findEnvironment(envName);
+ if (env == null) {
+ throw new IllegalArgumentException
+ ("Invalid environment name '" + envName + "'");
+ }
+ nresources.removeEnvironment(envName);
+
+ }
+
+
+ /**
+ * Remove any resource reference with the specified name.
+ *
+ * @param resourceName Name of the resource reference to remove
+ */
+ public void removeResource(String resourceName) {
+
+ resourceName = URLDecoder.decode(resourceName);
+ NamingResources nresources = getNamingResources();
+ if (nresources == null) {
+ return;
+ }
+ ContextResource resource = nresources.findResource(resourceName);
+ if (resource == null) {
+ throw new IllegalArgumentException
+ ("Invalid resource name '" + resourceName + "'");
+ }
+ nresources.removeResource(resourceName);
+ }
+
+
+ /**
+ * Remove any resource link with the specified name.
+ *
+ * @param resourceName Name of the resource reference to remove
+ */
+ public void removeResourceLink(String resourceLinkName) {
+
+ resourceLinkName = URLDecoder.decode(resourceLinkName);
+ NamingResources nresources = getNamingResources();
+ if (nresources == null) {
+ return;
+ }
+ ContextResourceLink resource =
nresources.findResourceLink(resourceLinkName);
+ if (resource == null) {
+ throw new IllegalArgumentException
+ ("Invalid resource name '" + resourceLinkName + "'");
+ }
+ nresources.removeResourceLink(resourceLinkName);
+ }
+
}
1.60 +71 -1
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml
Index: mbeans-descriptors.xml
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- mbeans-descriptors.xml 30 May 2002 19:43:29 -0000 1.59
+++ mbeans-descriptors.xml 6 Jun 2002 22:36:47 -0000 1.60
@@ -6,7 +6,7 @@
<!--
Descriptions of JMX MBeans for Catalina
- $Id: mbeans-descriptors.xml,v 1.59 2002/05/30 19:43:29 manveen Exp $
+ $Id: mbeans-descriptors.xml,v 1.60 2002/06/06 22:36:47 amyroh Exp $
-->
<mbeans-descriptors>
@@ -193,6 +193,28 @@
</mbean>
+ <mbean name="ContextResourceLink"
+ className="org.apache.catalina.mbeans.ClassNameMBean"
+ description="Representation of a resource link for a web application"
+ domain="Catalina"
+ group="Resources"
+ type="org.apache.catalina.deploy.ContextResourceLink">
+
+ <attribute name="global"
+ description="The global name of this resource"
+ type="java.lang.String"/>
+
+ <attribute name="name"
+ description="The name of this resource"
+ type="java.lang.String"/>
+
+ <attribute name="type"
+ description="The type of this resource"
+ type="java.lang.String"/>
+
+ </mbean>
+
+
<mbean name="CoyoteConnector"
className="org.apache.catalina.mbeans.ConnectorMBean"
description="Implementation of a Coyote connector"
@@ -1841,6 +1863,12 @@
description="The document root for this web application"
type="java.lang.String"/>
+ <attribute name="environments"
+ description="MBean Names of the set of defined environment entries
+ for this web application"
+ type="java.lang.String[]"
+ writeable="false"/>
+
<attribute name="managedResource"
description="The managed resource this MBean is associated with"
type="java.lang.Object"/>
@@ -1858,6 +1886,12 @@
description="The reloadable flag for this web application"
type="boolean"/>
+ <attribute name="resources"
+ description="MBean Names of all the defined resource references
+ for this application."
+ type="java.lang.String[]"
+ writeable="false"/>
+
<attribute name="useNaming"
description="Create a JNDI naming context for this application?"
is="true"
@@ -1866,6 +1900,42 @@
<attribute name="workDir"
description="The pathname to the work directory for this context"
type="java.lang.String"/>
+
+ <operation name="addEnvironment"
+ description="Add an environment entry for this web application"
+ impact="ACTION"
+ returnType="void">
+ <parameter name="envName"
+ description="New environment entry name"
+ type="java.lang.String"/>
+ </operation>
+
+ <operation name="addResource"
+ description="Add a resource reference for this web application"
+ impact="ACTION"
+ returnType="void">
+ <parameter name="resourceName"
+ description="New resource reference name"
+ type="java.lang.String"/>
+ </operation>
+
+ <operation name="removeEnvironment"
+ description="Remove any environment entry with the specified name"
+ impact="ACTION"
+ returnType="void">
+ <parameter name="envName"
+ description="Name of the environment entry to remove"
+ type="java.lang.String"/>
+ </operation>
+
+ <operation name="removeResource"
+ description="Remove any resource reference with the specified name"
+ impact="ACTION"
+ returnType="void">
+ <parameter name="resourceName"
+ description="Name of the resource reference to remove"
+ type="java.lang.String"/>
+ </operation>
</mbean>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>