ASF Bugzilla – Attachment 25228 Details for
Bug 49045
JMX Enhancement- Provision of MBeanFactory createStandardService
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Adding createStandardService method to MBeanFactory
createService_patch1.txt (text/plain), 8.85 KB, created by
chamith buddhika
on 2010-04-04 06:24:32 UTC
(
hide
)
Description:
Adding createStandardService method to MBeanFactory
Filename:
MIME Type:
Creator:
chamith buddhika
Created:
2010-04-04 06:24:32 UTC
Size:
8.85 KB
patch
obsolete
>Index: catalina/mbeans/MBeanFactory.java >=================================================================== >--- catalina/mbeans/MBeanFactory.java (revision 930191) >+++ catalina/mbeans/MBeanFactory.java (working copy) >@@ -36,6 +36,7 @@ > import org.apache.catalina.core.StandardContext; > import org.apache.catalina.core.StandardEngine; > import org.apache.catalina.core.StandardHost; >+import org.apache.catalina.core.StandardServer; > import org.apache.catalina.core.StandardService; > import org.apache.catalina.loader.WebappLoader; > import org.apache.catalina.realm.DataSourceRealm; >@@ -51,6 +52,7 @@ > import org.apache.catalina.valves.RemoteHostValve; > import org.apache.catalina.valves.ValveBase; > import org.apache.tomcat.util.modeler.BaseModelMBean; >+import org.apache.tomcat.util.modeler.Registry; > > > /** >@@ -232,6 +234,69 @@ > > } > >+ private Server getServer(ObjectName oname) throws Exception{ >+ Server server=null; >+ >+ if(container instanceof Service){ >+ server=((StandardService)container).getServer(); >+ } else if(container instanceof Server){ >+ server=(Server)this.container; >+ } >+ >+ StandardServer standardServer=null; >+ if(server instanceof StandardServer){ >+ standardServer = (StandardServer)server; >+ } >+ >+ if(oname != null && standardServer != null >+ && !oname.getDomain().equals(standardServer.getObjectName().getDomain())){ >+ throw new Exception("Server with the domain is not found"); >+ } >+ >+ return server; >+ } >+ >+ /** >+ * Creates a new StandardService. >+ * >+ * @param parent MBean Name of the associated parent component (Server) >+ * @param name Name of this service >+ * @param container Name of the associated container (Engine) instance with this service >+ * @param domain Domain name for the container instance >+ * @param defaultHost Name of the default host to be used in the Engine >+ * @param baseDir Base directory value for Engine >+ * >+ * @exception Exception if an MBean cannot be created or registered >+ */ >+ public String createStandardService(String parent, String name, >+ String container, String domain, String defaultHost, String baseDir) throws Exception{ >+ >+ ObjectName pname = new ObjectName(parent); >+ Server server=getServer(pname); >+ StandardService service = new StandardService(); >+ service.setName(name); >+ >+ ObjectName oname; >+ if(domain != null){ >+ oname=new ObjectName(domain + ":type=Service,serviceName="+name); >+ }else{ >+ oname=new ObjectName(pname.getDomain() + ":type=Service,serviceName="+name); >+ } >+ >+ service.preRegister(Registry.getRegistry(null, null).getMBeanServer(), oname); >+ Registry.getRegistry(null, null).registerComponent(service, oname, null); >+ server.addService(service); >+ >+ StandardEngine engine = new StandardEngine(); >+ engine.setName( container ); >+ engine.setDomain(domain); >+ engine.setDefaultHost(defaultHost); >+ engine.setBaseDir(baseDir); >+ service.setContainer(engine); >+ >+ return (oname.toString()); >+ >+ } > > /** > * Create a new AccessLoggerValve. >@@ -685,7 +750,7 @@ > > } > >- >+ > /** > * Create a new StandardManager. > * >@@ -777,7 +842,22 @@ > > } > >- >+ /** >+ * Remove an existing Service. >+ * >+ * @param name MBean Name of the service to remove >+ * >+ * @exception Exception if a component cannot be removed >+ */ >+ public void removeService(String name) throws Exception{ >+ >+ ObjectName oname = new ObjectName(name); >+ Service service = getService(oname); >+ Server server = service.getServer(); >+ server.removeService(service); >+ >+ } >+ > /** > * Remove an existing Connector. > * >Index: catalina/mbeans/mbeans-descriptors.xml >=================================================================== >--- catalina/mbeans/mbeans-descriptors.xml (revision 930191) >+++ catalina/mbeans/mbeans-descriptors.xml (working copy) >@@ -27,6 +27,30 @@ > <!-- value is the object name of the corresponding MBean for the new --> > <!-- component. --> > >+ <operation name="createStandardService" >+ description="Create a new StandardService" >+ impact="ACTION" >+ returnType="java.lang.String"> >+ <parameter name="parent" >+ description="MBean Name of the associated parent component" >+ type="java.lang.String"/> >+ <parameter name="name" >+ description="Name of the service" >+ type="java.lang.String"/> >+ <parameter name="container" >+ description="Name of the associated container instance with the service" >+ type="java.lang.String"/> >+ <parameter name="domain" >+ description="JMX Domain for the new container. Nullable. Defaults to Server domain." >+ type="java.lang.String"/> >+ <parameter name="defaultHost" >+ description="Name of the default host to be used in the Engine" >+ type="java.lang.String"/> >+ <parameter name="baseDir" >+ description="Base directory value for Engine" >+ type="java.lang.String"/> >+ </operation> >+ > <operation name="createAccessLoggerValve" > description="Create a new AccessLoggerValve" > impact="ACTION" >@@ -264,9 +288,6 @@ > type="boolean"/> > </operation> > >- >- >- > <operation name="createStandardManager" > description="Create a new StandardManager" > impact="ACTION" >@@ -276,21 +297,6 @@ > type="java.lang.String"/> > </operation> > >- <operation name="createStandardService" >- description="Create a new StandardService" >- impact="ACTION" >- returnType="java.lang.String"> >- <parameter name="parent" >- description="MBean Name of the associated parent component" >- type="java.lang.String"/> >- <parameter name="name" >- description="Unique name of this Service" >- type="java.lang.String"/> >- <parameter name="domain" >- description="The domain of this Service" >- type="java.lang.String"/> >- </operation> >- > <operation name="createSystemErrLogger" > description="Create a new System Error Logger" > impact="ACTION" >Index: tomcat/util/modeler/BaseModelMBean.java >=================================================================== >--- tomcat/util/modeler/BaseModelMBean.java (revision 909236) >+++ tomcat/util/modeler/BaseModelMBean.java (working copy) >@@ -291,7 +291,7 @@ > // Invoke the selected method on the appropriate object > Object result = null; > try { >- if( method.getDeclaringClass().isAssignableFrom( this.getClass()) ) { >+ if( method.getDeclaringClass().isAssignableFrom( this.getClass()) && !method.getDeclaringClass().equals(this.getClass()) ) { > result = method.invoke(this, params ); > } else { > result = method.invoke(resource, params); >Index: tomcat/util/modeler/ManagedBean.java >=================================================================== >--- tomcat/util/modeler/ManagedBean.java (revision 909236) >+++ tomcat/util/modeler/ManagedBean.java (working copy) >@@ -599,18 +599,12 @@ > types[i] = BaseModelMBean.getAttributeClass(signature[i]); > } > >- // Locate the method to be invoked, either in this MBean itself >- // or in the corresponding managed resource >+ // Locate the method to be invoked, either in the corresponding managed resource >+ // or in this MBean itself > // FIXME - Accessible methods in superinterfaces? > Object object = null; > Exception exception = null; > try { >- object = bean; >- method = object.getClass().getMethod(aname, types); >- } catch (NoSuchMethodException e) { >- exception = e; >- } >- try { > if ((method == null) && (resource != null)) { > object = resource; > method = object.getClass().getMethod(aname, types); >@@ -618,6 +612,16 @@ > } catch (NoSuchMethodException e) { > exception = e; > } >+ >+ if(method == null){ >+ try { >+ object = bean; >+ method = object.getClass().getMethod(aname, types); >+ } catch (NoSuchMethodException e) { >+ exception = e; >+ } >+ } >+ > if (method == null) { > throw new ReflectionException(exception, "Cannot find method " > + aname + " with this signature");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 49045
:
25228
|
25277