amyroh 2003/08/28 19:35:57 Modified: catalina/src/share/org/apache/catalina/mbeans ConnectorMBean.java catalina/src/share/org/apache/coyote/tomcat5 mbeans-descriptors.xml Log: Add ConnectorMBean implementation and force CoyoteConnector to use the ConnectorMBean for its configuration. Revision Changes Path 1.2 +128 -176 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/ConnectorMBean.java Index: ConnectorMBean.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/ConnectorMBean.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ConnectorMBean.java 18 Jul 2002 16:47:58 -0000 1.1 +++ ConnectorMBean.java 29 Aug 2003 02:35:57 -0000 1.2 @@ -1,4 +1,4 @@ -/* +/*l * $Header$ * $Revision$ * $Date$ @@ -64,16 +64,24 @@ package org.apache.catalina.mbeans; import java.lang.reflect.Method; +import javax.management.Attribute; +import javax.management.AttributeNotFoundException; +import javax.management.InstanceNotFoundException; import javax.management.MBeanException; +import javax.management.ReflectionException; import javax.management.RuntimeOperationsException; +import javax.management.modelmbean.InvalidTargetObjectTypeException; import org.apache.catalina.Connector; import org.apache.catalina.Service; import org.apache.commons.modeler.BaseModelMBean; +import org.apache.coyote.ProtocolHandler; +import org.apache.coyote.tomcat5.CoyoteConnector; +import org.apache.tomcat.util.IntrospectionUtils; /** * <p>A <strong>ModelMBean</strong> implementation for the - * <code>org.apache.coyote.tomcat4.CoyoteConnector</code> component.</p> + * <code>org.apache.coyote.tomcat5.CoyoteConnector</code> component.</p> * * @author Amy Roh * @version $Revision$ $Date$ @@ -105,191 +113,135 @@ // ------------------------------------------------------------- Attributes - - // ------------------------------------------------------------- Operations - - /** - * Return Client authentication info + * Obtain and return the value of a specific attribute of this MBean. * - * @exception Exception if an MBean cannot be created or registered - */ - public boolean getClientAuth() - throws Exception { - - Object clientAuthObj = null; - Class coyoteConnectorCls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); - if (coyoteConnectorCls.isInstance(this.resource)) { - // get factory - Method meth1 = coyoteConnectorCls.getMethod("getFactory", null); - Object factory = meth1.invoke(this.resource, null); - Class coyoteServerSocketFactoryCls = Class.forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory"); - if (coyoteServerSocketFactoryCls.isInstance(factory)) { - // get clientAuth - Method meth2 = coyoteServerSocketFactoryCls.getMethod("getClientAuth", null); - clientAuthObj = meth2.invoke(factory, null); - } - - } - if (clientAuthObj instanceof Boolean) { - return ((Boolean)clientAuthObj).booleanValue(); - } else return false; - - } - - - /** - * Set Client authentication info + * @param name Name of the requested attribute * - * @exception Exception if an MBean cannot be created or registered + * @exception AttributeNotFoundException if this attribute is not + * supported by this MBean + * @exception MBeanException if the initializer of an object + * throws an exception + * @exception ReflectionException if a Java reflection exception + * occurs when invoking the getter */ - public void setClientAuth(boolean clientAuth) - throws Exception { - - Class coyoteConnectorCls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); - if (coyoteConnectorCls.isInstance(this.resource)) { - // get factory - Method meth1 = coyoteConnectorCls.getMethod("getFactory", null); - Object factory = meth1.invoke(this.resource, null); - Class coyoteServerSocketFactoryCls = Class.forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory"); - if (coyoteServerSocketFactoryCls.isInstance(factory)) { - // set clientAuth - Class partypes2 [] = new Class[1]; - partypes2[0] = Boolean.TYPE; - Method meth2 = coyoteServerSocketFactoryCls.getMethod("setClientAuth", partypes2); - Object arglist2[] = new Object[1]; - arglist2[0] = new Boolean(clientAuth); - meth2.invoke(factory, arglist2); - } - } - - } + public Object getAttribute(String name) + throws AttributeNotFoundException, MBeanException, + ReflectionException { + + Object attribute = null; + // Validate the input parameters + if (name == null) + throw new RuntimeOperationsException + (new IllegalArgumentException("Attribute name is null"), + "Attribute name is null"); + + CoyoteConnector connector = null; + try { + connector = (CoyoteConnector) getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + if (("algorithm").equals(name) || ("keystoreType").equals(name) || + ("maxThreads").equals(name) || ("maxSpareThreads").equals(name) || + ("minSpareThreads").equals(name)) { + + if (("keystoreType").equals(name)) { + name = "keyType"; + } + + ProtocolHandler protocolHandler = connector.getProtocolHandler(); + /* check the Protocol first, since JkCoyote has an independent + * configure method. + */ + try { + if( protocolHandler != null ) { + attribute = IntrospectionUtils.getAttribute(protocolHandler, name); + } + } catch (Exception e) { + throw new MBeanException(e); + } + //if( attribute == null ) { + // attribute = connector.getProperty(name); + //} + } else { + attribute = super.getAttribute(name); + } + + return attribute; - - /** - * Return keystoreFile - * - * @exception Exception if an MBean cannot be created or registered - */ - public String getKeystoreFile() - throws Exception { - - Object keystoreFileObj = null; - Class coyoteConnectorCls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); - if (coyoteConnectorCls.isInstance(this.resource)) { - // get keystoreFile - Method meth1 = coyoteConnectorCls.getMethod("getFactory", null); - Object factory = meth1.invoke(this.resource, null); - Class coyoteServerSocketFactoryCls = Class.forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory"); - if (coyoteServerSocketFactoryCls.isInstance(factory)) { - // get keystoreFile - Method meth2 = coyoteServerSocketFactoryCls.getMethod("getKeystoreFile", null); - keystoreFileObj = meth2.invoke(factory, null); - } - } - - if (keystoreFileObj == null) { - return null; - } else { - return keystoreFileObj.toString(); - } - } - + /** - * Set keystoreFile + * Set the value of a specific attribute of this MBean. * - * @exception Exception if an MBean cannot be created or registered - */ - public void setKeystoreFile(String keystoreFile) - throws Exception { - - if (keystoreFile == null) { - keystoreFile = ""; - } - Class coyoteConnectorCls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); - if (coyoteConnectorCls.isInstance(this.resource)) { - // get factory - Method meth1 = coyoteConnectorCls.getMethod("getFactory", null); - Object factory = meth1.invoke(this.resource, null); - Class coyoteServerSocketFactoryCls = Class.forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory"); - if (coyoteServerSocketFactoryCls.isInstance(factory)) { - // set keystoreFile - Class partypes2 [] = new Class[1]; - String str = new String(); - partypes2[0] = str.getClass(); - Method meth2 = coyoteServerSocketFactoryCls.getMethod("setKeystoreFile", partypes2); - Object arglist2[] = new Object[1]; - arglist2[0] = keystoreFile; - meth2.invoke(factory, arglist2); - } - - } - } - - - /** - * Return keystorePass + * @param attribute The identification of the attribute to be set + * and the new value * - * @exception Exception if an MBean cannot be created or registered + * @exception AttributeNotFoundException if this attribute is not + * supported by this MBean + * @exception MBeanException if the initializer of an object + * throws an exception + * @exception ReflectionException if a Java reflection exception + * occurs when invoking the getter */ - public String getKeystorePass() - throws Exception { - - Object keystorePassObj = null; - Class coyoteConnectorCls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); - if (coyoteConnectorCls.isInstance(this.resource)) { - // get factory - Method meth1 = coyoteConnectorCls.getMethod("getFactory", null); - Object factory = meth1.invoke(this.resource, null); - Class coyoteServerSocketFactoryCls = Class.forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory"); - if (coyoteServerSocketFactoryCls.isInstance(factory)) { - // get keystorePass - Method meth2 = coyoteServerSocketFactoryCls.getMethod("getKeystorePass", null); - keystorePassObj = meth2.invoke(factory, null); + public void setAttribute(Attribute attribute) + throws AttributeNotFoundException, MBeanException, + ReflectionException { + + // Validate the input parameters + if (attribute == null) + throw new RuntimeOperationsException + (new IllegalArgumentException("Attribute is null"), + "Attribute is null"); + String name = attribute.getName(); + Object value = attribute.getValue(); + if (name == null) + throw new RuntimeOperationsException + (new IllegalArgumentException("Attribute name is null"), + "Attribute name is null"); + + CoyoteConnector connector = null; + try { + connector = (CoyoteConnector) getManagedResource(); + } catch (InstanceNotFoundException e) { + throw new MBeanException(e); + } catch (InvalidTargetObjectTypeException e) { + throw new MBeanException(e); + } + + if (("algorithm").equals(name) || ("keystoreType").equals(name) || + ("maxThreads").equals(name) || ("maxSpareThreads").equals(name) || + ("minSpareThreads").equals(name)) { + + if (("keystoreType").equals(name)) { + name = "keyType"; } - - } - - if (keystorePassObj == null) { - return null; - } else { - return keystorePassObj.toString(); - } - - } - - - /** - * Set keystorePass - * - * @exception Exception if an MBean cannot be created or registered - */ - public void setKeystorePass(String keystorePass) - throws Exception { - if (keystorePass == null) { - keystorePass = ""; - } - Class coyoteConnectorCls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); - if (coyoteConnectorCls.isInstance(this.resource)) { - // get factory - Method meth1 = coyoteConnectorCls.getMethod("getFactory", null); - Object factory = meth1.invoke(this.resource, null); - Class coyoteServerSocketFactoryCls = Class.forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory"); - if (coyoteServerSocketFactoryCls.isInstance(factory)) { - // set keystorePass - Class partypes2 [] = new Class[1]; - String str = new String(); - partypes2[0] = str.getClass(); - Method meth2 = coyoteServerSocketFactoryCls.getMethod("setKeystorePass", partypes2); - Object arglist2[] = new Object[1]; - arglist2[0] = keystorePass; - meth2.invoke(factory, arglist2); + ProtocolHandler protocolHandler = connector.getProtocolHandler(); + /* check the Protocol first, since JkCoyote has an independent + * configure method. + */ + try { + if( protocolHandler != null ) { + IntrospectionUtils.setAttribute(protocolHandler, name, value); + } + } catch (Exception e) { + throw new MBeanException(e); } - } + + } else { + super.setAttribute(attribute); + } + } + + + // ------------------------------------------------------------- Operations } 1.8 +18 -0 jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/mbeans-descriptors.xml Index: mbeans-descriptors.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/mbeans-descriptors.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- mbeans-descriptors.xml 25 Aug 2003 22:08:24 -0000 1.7 +++ mbeans-descriptors.xml 29 Aug 2003 02:35:57 -0000 1.8 @@ -2,6 +2,7 @@ <mbeans-descriptors> <mbean name="CoyoteConnector" + className="org.apache.catalina.mbeans.ConnectorMBean" description="Implementation of a Coyote connector" domain="Catalina" group="Connector" @@ -86,6 +87,23 @@ <attribute name="maxProcessors" description="The maximum number of processors allowed" + type="int"/> + + <attribute name="minProcessors" + description="The minimum number of processors to start at + initialization time" + type="int"/> + + <attribute name="maxSpareThreads" + description="The maximum number of unused request processing threads" + type="int"/> + + <attribute name="maxThreads" + description="The maximum number of request processing threads to be created" + type="int"/> + + <attribute name="minSpareThreads" + description="The number of request processing threads that will be created" type="int"/> <attribute name="minProcessors"
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]