From 7b46d1d489f336316cee2fc2ab5330c3a818d5d9 Mon Sep 17 00:00:00 2001 From: costin Date: Tue, 20 Jun 2006 21:31:42 +0000 Subject: [PATCH] Update the modeler with the sandbox version, using dynamic mbeans instead of model mbeans. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@415811 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tomcat/util/modeler/AttributeInfo.java | 180 +------ .../apache/tomcat/util/modeler/BaseModelMBean.java | 598 ++++++--------------- .../tomcat/util/modeler/BaseNotification.java | 88 --- .../tomcat/util/modeler/ConstructorInfo.java | 127 +---- .../apache/tomcat/util/modeler/FeatureInfo.java | 54 +- java/org/apache/tomcat/util/modeler/FieldInfo.java | 60 --- java/org/apache/tomcat/util/modeler/JndiJmx.java | 227 -------- .../apache/tomcat/util/modeler/ManagedBean.java | 437 +++++++++------ .../tomcat/util/modeler/NotificationInfo.java | 15 +- .../apache/tomcat/util/modeler/OperationInfo.java | 138 +---- .../apache/tomcat/util/modeler/ParameterInfo.java | 102 +--- java/org/apache/tomcat/util/modeler/Registry.java | 126 ++--- .../modules/MbeansDescriptorsDOMSource.java | 20 +- .../modules/MbeansDescriptorsDigesterSource.java | 4 +- .../MbeansDescriptorsDynamicMBeanSource.java | 157 ------ .../MbeansDescriptorsIntrospectionSource.java | 25 +- 16 files changed, 584 insertions(+), 1774 deletions(-) delete mode 100644 java/org/apache/tomcat/util/modeler/BaseNotification.java delete mode 100644 java/org/apache/tomcat/util/modeler/FieldInfo.java delete mode 100644 java/org/apache/tomcat/util/modeler/JndiJmx.java delete mode 100644 java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDynamicMBeanSource.java diff --git a/java/org/apache/tomcat/util/modeler/AttributeInfo.java b/java/org/apache/tomcat/util/modeler/AttributeInfo.java index f806a1d48..b69c4e53f 100644 --- a/java/org/apache/tomcat/util/modeler/AttributeInfo.java +++ b/java/org/apache/tomcat/util/modeler/AttributeInfo.java @@ -19,10 +19,8 @@ package org.apache.tomcat.util.modeler; import java.io.Serializable; -import java.lang.reflect.Method; -import javax.management.Descriptor; -import javax.management.modelmbean.ModelMBeanAttributeInfo; +import javax.management.MBeanAttributeInfo; /** @@ -30,58 +28,22 @@ import javax.management.modelmbean.ModelMBeanAttributeInfo; * descriptor.

* * @author Craig R. McClanahan - * @version $Revision: 155428 $ $Date: 2005-02-26 14:12:25 +0100 (sam., 26 févr. 2005) $ */ - public class AttributeInfo extends FeatureInfo implements Serializable { static final long serialVersionUID = -2511626862303972143L; // ----------------------------------------------------- Instance Variables - - - /** - * The ModelMBeanAttributeInfo object that corresponds - * to this AttributeInfo instance. - */ - protected transient ModelMBeanAttributeInfo info = null; protected String displayName = null; + + // Information about the method to use protected String getMethod = null; protected String setMethod = null; - - protected transient Method getMethodObj = null; - protected transient Method setMethodObj = null; - protected boolean readable = true; protected boolean writeable = true; - protected boolean is = false; - protected String type = null; - - protected String persist; - protected String defaultStringValue; + // ------------------------------------------------------------- Properties - - /** - * Override the description property setter. - * - * @param description The new description - */ - public void setDescription(String description) { - super.setDescription(description); - this.info = null; - } - - /** - * Override the name property setter. - * - * @param name The new name - */ - public void setName(String name) { - super.setName(name); - this.info = null; - } - /** * The display name of this attribute. */ @@ -97,28 +59,13 @@ public class AttributeInfo extends FeatureInfo implements Serializable { * The name of the property getter method, if non-standard. */ public String getGetMethod() { + if(getMethod == null) + getMethod = getMethodName(getName(), true, isIs()); return (this.getMethod); } public void setGetMethod(String getMethod) { this.getMethod = getMethod; - this.info = null; - } - - public Method getGetMethodObj() { - return getMethodObj; - } - - public void setGetMethodObj(Method getMethodObj) { - this.getMethodObj = getMethodObj; - } - - public Method getSetMethodObj() { - return setMethodObj; - } - - public void setSetMethodObj(Method setMethodObj) { - this.setMethodObj = setMethodObj; } /** @@ -130,7 +77,6 @@ public class AttributeInfo extends FeatureInfo implements Serializable { public void setIs(boolean is) { this.is = is; - this.info = null; } @@ -143,7 +89,6 @@ public class AttributeInfo extends FeatureInfo implements Serializable { public void setReadable(boolean readable) { this.readable = readable; - this.info = null; } @@ -151,28 +96,15 @@ public class AttributeInfo extends FeatureInfo implements Serializable { * The name of the property setter method, if non-standard. */ public String getSetMethod() { + if( setMethod == null ) + setMethod = getMethodName(getName(), false, false); return (this.setMethod); } public void setSetMethod(String setMethod) { this.setMethod = setMethod; - this.info = null; - } - - - /** - * The fully qualified Java class name of this attribute. - */ - public String getType() { - return (this.type); - } - - public void setType(String type) { - this.type = type; - this.info = null; } - /** * Is this attribute writeable by management applications? */ @@ -182,35 +114,8 @@ public class AttributeInfo extends FeatureInfo implements Serializable { public void setWriteable(boolean writeable) { this.writeable = writeable; - this.info = null; - } - - /** Persistence policy. - * All persistent attributes should have this attribute set. - * Valid values: - * ??? - */ - public String getPersist() { - return persist; } - public void setPersist(String persist) { - this.persist = persist; - } - - /** Default value. If set, it can provide info to the user and - * it can be used by persistence mechanism to generate a more compact - * representation ( a value may not be saved if it's default ) - */ - public String getDefault() { - return defaultStringValue; - } - - public void setDefault(String defaultStringValue) { - this.defaultStringValue = defaultStringValue; - } - - // --------------------------------------------------------- Public Methods @@ -218,74 +123,15 @@ public class AttributeInfo extends FeatureInfo implements Serializable { * Create and return a ModelMBeanAttributeInfo object that * corresponds to the attribute described by this instance. */ - public ModelMBeanAttributeInfo createAttributeInfo() { + MBeanAttributeInfo createAttributeInfo() { // Return our cached information (if any) - if (info != null) - return (info); - if((getMethodObj != null) || (setMethodObj != null) ) { - try { - info=new ModelMBeanAttributeInfo(getName(), getDescription(), - getMethodObj, setMethodObj); - return info; - } catch( Exception ex) { - ex.printStackTrace(); - } + if (info == null) { + info = new MBeanAttributeInfo(getName(), getType(), getDescription(), + isReadable(), isWriteable(), false); } - - // Create and return a new information object - info = new ModelMBeanAttributeInfo - (getName(), getType(), getDescription(), - isReadable(), isWriteable(), false); - Descriptor descriptor = info.getDescriptor(); - if (getDisplayName() != null) - descriptor.setField("displayName", getDisplayName()); - if (isReadable()) { - if (getGetMethod() != null) - descriptor.setField("getMethod", getGetMethod()); - else - descriptor.setField("getMethod", - getMethodName(getName(), true, isIs())); - } - if (isWriteable()) { - if (getSetMethod() != null) - descriptor.setField("setMethod", getSetMethod()); - else - descriptor.setField("setMethod", - getMethodName(getName(), false, false)); - } - addFields(descriptor); - info.setDescriptor(descriptor); - return (info); - - } - - - /** - * Return a string representation of this attribute descriptor. - */ - public String toString() { - - StringBuffer sb = new StringBuffer("AttributeInfo["); - sb.append("name="); - sb.append(name); - sb.append(", description="); - sb.append(description); - if (!readable) { - sb.append(", readable="); - sb.append(readable); - } - sb.append(", type="); - sb.append(type); - if (!writeable) { - sb.append(", writeable="); - sb.append(writeable); - } - sb.append("]"); - return (sb.toString()); - + return (MBeanAttributeInfo)info; } - // -------------------------------------------------------- Private Methods diff --git a/java/org/apache/tomcat/util/modeler/BaseModelMBean.java b/java/org/apache/tomcat/util/modeler/BaseModelMBean.java index f633beb1c..28b8c9c8b 100644 --- a/java/org/apache/tomcat/util/modeler/BaseModelMBean.java +++ b/java/org/apache/tomcat/util/modeler/BaseModelMBean.java @@ -20,15 +20,12 @@ package org.apache.tomcat.util.modeler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Hashtable; import java.util.Iterator; import javax.management.Attribute; import javax.management.AttributeChangeNotification; import javax.management.AttributeList; import javax.management.AttributeNotFoundException; -import javax.management.Descriptor; import javax.management.DynamicMBean; import javax.management.InstanceNotFoundException; import javax.management.InvalidAttributeValueException; @@ -45,30 +42,40 @@ import javax.management.ObjectName; import javax.management.ReflectionException; import javax.management.RuntimeErrorException; import javax.management.RuntimeOperationsException; -import javax.management.ServiceNotFoundException; -import javax.management.modelmbean.DescriptorSupport; import javax.management.modelmbean.InvalidTargetObjectTypeException; -import javax.management.modelmbean.ModelMBean; -import javax.management.modelmbean.ModelMBeanAttributeInfo; -import javax.management.modelmbean.ModelMBeanInfo; -import javax.management.modelmbean.ModelMBeanInfoSupport; -import javax.management.modelmbean.ModelMBeanNotificationInfo; -import javax.management.modelmbean.ModelMBeanOperationInfo; +import javax.management.modelmbean.ModelMBeanNotificationBroadcaster; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.tomcat.util.modeler.modules.ModelerSource; -// TODO: enable ant-like substitutions ? ( or at least discuss it ) +/* + * Changes from commons.modeler: + * + * - use DynamicMBean + * - remove methods not used in tomcat and redundant/not very generic + * - must be created from the ManagedBean - I don't think there were any direct + * uses, but now it is required. + * - some of the gratuituous flexibility removed - instead this is more predictive and + * strict with the use cases. + * - all Method and metadata is stored in ManagedBean. BaseModelBMean and ManagedBean act + * like Object and Class. + * - setModelMBean is no longer called on resources ( not used in tomcat ) + * - no caching of Methods for now - operations and setters are not called repeatedly in most + * management use cases. Getters should't be called very frequently either - and even if they + * are, the overhead of getting the method should be small compared with other JMX costs ( RMI, etc ). + * We can add getter cache if needed. + * - removed unused constructor, fields + * + * TODO: + * - clean up catalina.mbeans, stop using weird inheritance + */ /** - *

Basic implementation of the ModelMBean interface, which + *

Basic implementation of the DynamicMBean interface, which * supports the minimal requirements of the interface contract.

* *

This can be used directly to wrap an existing java bean, or inside - * an mlet or anywhere an MBean would be used. The String parameter - * passed to the constructor will be used to construct an instance of the - * real object that we wrap. + * an mlet or anywhere an MBean would be used. * * Limitations: *