You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by am...@apache.org on 2002/06/12 09:39:24 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans MBeanUtils.java NamingResourcesMBean.java ServerLifecycleListener.java mbeans-descriptors.xml
amyroh 2002/06/12 00:39:24
Modified: catalina/src/share/org/apache/catalina/mbeans
MBeanUtils.java NamingResourcesMBean.java
ServerLifecycleListener.java mbeans-descriptors.xml
Log:
Add JNDI resources support for Context.
Revision Changes Path
1.40 +84 -14 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.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- MBeanUtils.java 9 Jun 2002 00:23:27 -0000 1.39
+++ MBeanUtils.java 12 Jun 2002 07:39:23 -0000 1.40
@@ -921,8 +921,25 @@
throws MalformedObjectNameException {
ObjectName name = null;
- name = new ObjectName(domain + ":type=Environment,name=" +
+ Object container =
+ environment.getNamingResources().getContainer();
+ if (container instanceof Server) {
+ name = new ObjectName(domain + ":type=Environment,name=" +
environment.getName());
+ } else if (container instanceof Context) {
+ String path = ((Context)container).getPath();
+ if (path.length() < 1)
+ path = "/";
+ name = new ObjectName(domain + ":type=Environment,name=" +
+ environment.getName() + ",path=" +
+ path);
+ } else if (container instanceof DefaultContext) {
+ String defaultContextName = ((DefaultContext)container).getName();
+ name = new ObjectName(domain + ":type=Environment,name=" +
+ environment.getName() + ",defaultContext=" +
+ defaultContextName);
+ }
+
return (name);
}
@@ -943,9 +960,28 @@
ObjectName name = null;
String encodedResourceName = encodeStr(resource.getName());
- name = new ObjectName(domain + ":type=Resource,class=" +
+ Object container =
+ resource.getNamingResources().getContainer();
+ if (container instanceof Server) {
+ name = new ObjectName(domain + ":type=Resource,class=" +
resource.getType()+",name=" +
encodedResourceName);
+ } else if (container instanceof Context) {
+ String path = ((Context)container).getPath();
+ if (path.length() < 1)
+ path = "/";
+ name = new ObjectName(domain + ":type=Resource,class=" +
+ resource.getType()+",name=" +
+ encodedResourceName + ",path=" +
+ path);
+ } else if (container instanceof DefaultContext) {
+ String defaultContextName = ((DefaultContext)container).getName();
+ name = new ObjectName(domain + ":type=Resource,class=" +
+ resource.getType()+",name=" +
+ encodedResourceName + ",defaultContext=" +
+ defaultContextName);
+ }
+
return (name);
}
@@ -966,9 +1002,28 @@
ObjectName name = null;
String encodedResourceLinkName = encodeStr(resourceLink.getName());
- name = new ObjectName(domain + ":type=ResourceLink,class=" +
+ Object container =
+ resourceLink.getNamingResources().getContainer();
+ if (container instanceof Server) {
+ name = new ObjectName(domain + ":type=ResourceLink,class=" +
resourceLink.getType()+",name=" +
encodedResourceLinkName);
+ } else if (container instanceof Context) {
+ String path = ((Context)container).getPath();
+ if (path.length() < 1)
+ path = "/";
+ name = new ObjectName(domain + ":type=ResourceLink,class=" +
+ resourceLink.getType()+",name=" +
+ encodedResourceLinkName + ",path=" +
+ path);
+ } else if (container instanceof DefaultContext) {
+ String defaultContextName = ((DefaultContext)container).getName();
+ name = new ObjectName(domain + ":type=ResourceLink,class=" +
+ resourceLink.getType()+",name=" +
+ encodedResourceLinkName + ",defaultContext=" +
+ defaultContextName);
+ }
+
return (name);
}
@@ -1210,16 +1265,31 @@
* <code>Server</code> object.
*
* @param domain Domain in which this name is to be created
- * @param resource The NamingResources to be named
+ * @param resources The NamingResources to be named
*
* @exception MalformedObjectNameException if a name cannot be created
*/
public static ObjectName createObjectName(String domain,
- NamingResources resource)
+ NamingResources resources)
throws MalformedObjectNameException {
ObjectName name = null;
- name = new ObjectName(domain + ":type=NamingResources");
+ Object container = resources.getContainer();
+ if (container instanceof Server) {
+ name = new ObjectName(domain + ":type=NamingResources");
+ } else if (container instanceof Context) {
+ String path = ((Context)container).getPath();
+ if (path.length() < 1)
+ path = "/";
+ name = new ObjectName(domain + ":type=NamingResources,path=" +
+ path);
+ } else if (container instanceof DefaultContext) {
+ String defaultContextName = ((DefaultContext)container).getName();
+ name = new ObjectName(domain +
+ ":type=NamingResources,defaultContext=" +
+ defaultContextName);
+ }
+
return (name);
}
@@ -1815,14 +1885,14 @@
* Deregister the MBean for this
* <code>NamingResources</code> object.
*
- * @param resource The NamingResources to be managed
+ * @param resources The NamingResources to be managed
*
* @exception Exception if an MBean cannot be deregistered
*/
- public static void destroyMBean(NamingResources resource)
+ public static void destroyMBean(NamingResources resources)
throws Exception {
- String mname = createManagedName(resource);
+ String mname = createManagedName(resources);
ManagedBean managed = registry.findManagedBean(mname);
if (managed == null) {
return;
@@ -1830,7 +1900,7 @@
String domain = managed.getDomain();
if (domain == null)
domain = mserver.getDefaultDomain();
- ObjectName oname = createObjectName(domain, resource);
+ ObjectName oname = createObjectName(domain, resources);
mserver.unregisterMBean(oname);
}
1.7 +81 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/NamingResourcesMBean.java
Index: NamingResourcesMBean.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/NamingResourcesMBean.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NamingResourcesMBean.java 13 May 2002 18:25:47 -0000 1.6
+++ NamingResourcesMBean.java 12 Jun 2002 07:39:23 -0000 1.7
@@ -71,6 +71,7 @@
import javax.management.RuntimeOperationsException;
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;
@@ -171,7 +172,30 @@
return ((String[]) results.toArray(new String[results.size()]));
}
+
+
+ /**
+ * Return the MBean Names of all the defined resource link references for
+ * this application.
+ */
+ public String[] getResourceLinks() {
+
+ ContextResourceLink[] resourceLinks =
+ ((NamingResources)this.resource).findResourceLinks();
+ ArrayList results = new ArrayList();
+ for (int i = 0; i < resourceLinks.length; i++) {
+ try {
+ ObjectName oname =
+ MBeanUtils.createObjectName(managed.getDomain(), resourceLinks[i]);
+ results.add(oname.toString());
+ } catch (MalformedObjectNameException e) {
+ throw new IllegalArgumentException
+ ("Cannot create object name for resource " + resourceLinks[i]);
+ }
+ }
+ return ((String[]) results.toArray(new String[results.size()]));
+ }
// ------------------------------------------------------------- Operations
@@ -238,6 +262,37 @@
/**
+ * Add a resource link reference for this web application.
+ *
+ * @param resourceLinkName New resource link reference name
+ */
+ public String addResourceLink(String resourceLinkName, String type)
+ throws MalformedObjectNameException {
+
+ NamingResources nresources = (NamingResources) this.resource;
+ 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.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
@@ -276,6 +331,28 @@
("Invalid resource name '" + resourceName + "'");
}
nresources.removeResource(resourceName);
+ }
+
+
+ /**
+ * Remove any resource link reference with the specified name.
+ *
+ * @param resourceLinkName Name of the resource link reference to remove
+ */
+ public void removeResourceLink(String resourceLinkName) {
+
+ resourceLinkName = URLDecoder.decode(resourceLinkName);
+ NamingResources nresources = (NamingResources) this.resource;
+ if (nresources == null) {
+ return;
+ }
+ ContextResourceLink resourceLink =
+ nresources.findResourceLink(resourceLinkName);
+ if (resourceLink == null) {
+ throw new IllegalArgumentException
+ ("Invalid resource Link name '" + resourceLinkName + "'");
+ }
+ nresources.removeResourceLink(resourceLinkName);
}
}
1.27 +62 -9 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ServerLifecycleListener.java
Index: ServerLifecycleListener.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ServerLifecycleListener.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- ServerLifecycleListener.java 9 Jun 2002 00:23:27 -0000 1.26
+++ ServerLifecycleListener.java 12 Jun 2002 07:39:23 -0000 1.27
@@ -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;
@@ -469,7 +470,26 @@
}
+
+ /**
+ * Create the MBeans for the specified ContextResourceLink entry.
+ *
+ * @param resourceLink ContextResourceLink for which to create MBeans
+ *
+ * @exception Exception if an exception is thrown during MBean creation
+ */
+ protected void createMBeans(ContextResourceLink resourceLink)
+ throws Exception {
+ // Create the MBean for the ContextResourceLink itself
+ if (debug >= 3) {
+ log("Creating MBean for ContextResourceLink " + resourceLink);
+ }
+ MBeanUtils.createMBean(resourceLink);
+
+ }
+
+
/**
* Create the MBeans for the specified Engine and its nested components.
*
@@ -619,8 +639,12 @@
for (int i = 0; i < cresources.length; i++) {
createMBeans(cresources[i]);
}
-
- // FIXME - Add other resource types when supported by admin tool
+
+ // Create the MBeans for each child resource link entry
+ ContextResourceLink cresourcelinks[] = resources.findResourceLinks();
+ for (int i = 0; i < cresourcelinks.length; i++) {
+ createMBeans(cresourcelinks[i]);
+ }
}
@@ -794,6 +818,12 @@
MBeanUtils.destroyMBean(cLoader);
}
+ // Destroy the MBeans for the NamingResources (if any)
+ NamingResources resources = context.getNamingResources();
+ if (resources != null) {
+ destroyMBeans(resources);
+ }
+
// deregister the MBean for the Context itself
if (debug >= 4)
log("Destroying MBean for Context " + context);
@@ -845,6 +875,25 @@
/**
+ * Deregister the MBeans for the specified ContextResourceLink entry.
+ *
+ * @param resourceLink ContextResourceLink for which to destroy MBeans
+ *
+ * @exception Exception if an exception is thrown during MBean destruction
+ */
+ protected void destroyMBeans(ContextResourceLink resourceLink)
+ throws Exception {
+
+ // Destroy the MBean for the ContextResourceLink itself
+ if (debug >= 3) {
+ log("Destroying MBean for ContextResourceLink " + resourceLink);
+ }
+ MBeanUtils.destroyMBean(resourceLink);
+
+ }
+
+
+ /**
* Deregister the MBeans for the specified Engine and its nested
* components.
*
@@ -959,14 +1008,18 @@
*/
protected void destroyMBeans(NamingResources resources) throws Exception {
- // FIXME - Add other resource types when supported by admin tool
-
// Destroy the MBeans for each child resource entry
ContextResource cresources[] = resources.findResources();
for (int i = 0; i < cresources.length; i++) {
destroyMBeans(cresources[i]);
}
-
+
+ // Destroy the MBeans for each child resource link entry
+ ContextResourceLink cresourcelinks[] = resources.findResourceLinks();
+ for (int i = 0; i < cresourcelinks.length; i++) {
+ destroyMBeans(cresourcelinks[i]);
+ }
+
// Destroy the MBeans for each child environment entry
ContextEnvironment environments[] = resources.findEnvironments();
for (int i = 0; i < environments.length; i++) {
1.61 +19 -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.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- mbeans-descriptors.xml 6 Jun 2002 22:36:47 -0000 1.60
+++ mbeans-descriptors.xml 12 Jun 2002 07:39:23 -0000 1.61
@@ -1624,6 +1624,15 @@
type="java.lang.String"/>
</operation>
+ <operation name="addResourceLink"
+ description="Add a resource link reference for this web application"
+ impact="ACTION"
+ returnType="void">
+ <parameter name="resourceLinkName"
+ description="New resource reference name"
+ type="java.lang.String"/>
+ </operation>
+
<operation name="removeEnvironment"
description="Remove any environment entry with the specified name"
impact="ACTION"
@@ -1638,6 +1647,15 @@
impact="ACTION"
returnType="void">
<parameter name="resourceName"
+ description="Name of the resource reference to remove"
+ type="java.lang.String"/>
+ </operation>
+
+ <operation name="removeResourceLink"
+ description="Remove any resource link reference with the specified name"
+ impact="ACTION"
+ returnType="void">
+ <parameter name="resourceLinkName"
description="Name of the resource reference to remove"
type="java.lang.String"/>
</operation>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>