From d1330b3c3f7a839de3cb32f30552e4679f5eaff1 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 18 Nov 2008 00:47:36 +0000 Subject: [PATCH] Generics changes for o.a.t.util.modeler These changes identified a bunch of issues, the most serious of which was the loadDescriptors() method that sometimes returned List and sometimes List. Some callers expected this, some didn't. There are comments in the code identifying this as an issue. The fix I applied aligns with some commented out code that may have been part of an intended fix. There are still some deprecated methods that need to be cleaned up. With these changes Tomcat starts without error and JConsole shows all the mbeans I expect to see. There is plenty of further clean-up required here but I'll do that separately after the generics. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@718452 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/core/StandardEngine.java | 4 +- .../tomcat/util/modeler/BaseAttributeFilter.java | 4 +- .../apache/tomcat/util/modeler/BaseModelMBean.java | 10 +- .../util/modeler/BaseNotificationBroadcaster.java | 21 ++-- .../util/modeler/FixedNotificationFilter.java | 4 +- .../apache/tomcat/util/modeler/ManagedBean.java | 27 ++--- java/org/apache/tomcat/util/modeler/Registry.java | 113 +++++++++------------ .../apache/tomcat/util/modeler/RegistryMBean.java | 7 +- .../modules/MbeansDescriptorsDOMSource.java | 10 +- .../modules/MbeansDescriptorsDigesterSource.java | 22 ++-- .../MbeansDescriptorsIntrospectionSource.java | 66 ++++++------ .../modules/MbeansDescriptorsSerSource.java | 12 +-- .../tomcat/util/modeler/modules/MbeansSource.java | 17 ++-- .../util/modeler/modules/MbeansSourceMBean.java | 4 +- .../tomcat/util/modeler/modules/ModelerSource.java | 6 +- 15 files changed, 163 insertions(+), 164 deletions(-) diff --git a/java/org/apache/catalina/core/StandardEngine.java b/java/org/apache/catalina/core/StandardEngine.java index e6f01a8bd..d4be83814 100644 --- a/java/org/apache/catalina/core/StandardEngine.java +++ b/java/org/apache/catalina/core/StandardEngine.java @@ -115,7 +115,7 @@ public class StandardEngine /** Mbeans loaded by the engine. */ - private List mbeans; + private List mbeans; /** @@ -382,7 +382,7 @@ public class StandardEngine try { for( int i=0; i names = new HashSet(); // --------------------------------------------------------- Public Methods @@ -106,7 +106,7 @@ public class BaseAttributeFilter implements NotificationFilter { public String[] getNames() { synchronized (names) { - return ((String[]) names.toArray(new String[names.size()])); + return names.toArray(new String[names.size()]); } } diff --git a/java/org/apache/tomcat/util/modeler/BaseModelMBean.java b/java/org/apache/tomcat/util/modeler/BaseModelMBean.java index 924964e17..e4192a007 100644 --- a/java/org/apache/tomcat/util/modeler/BaseModelMBean.java +++ b/java/org/apache/tomcat/util/modeler/BaseModelMBean.java @@ -143,8 +143,8 @@ public class BaseModelMBean implements DynamicMBean, MBeanRegistration, ModelMBe // --------------------------------------------------- DynamicMBean Methods // TODO: move to ManagedBean - static final Object[] NO_ARGS_PARAM=new Object[0]; - static final Class[] NO_ARGS_PARAM_SIG=new Class[0]; + static final Object[] NO_ARGS_PARAM = new Object[0]; + static final Class[] NO_ARGS_PARAM_SIG = new Class[0]; protected String resourceType = null; @@ -180,7 +180,7 @@ public class BaseModelMBean implements DynamicMBean, MBeanRegistration, ModelMBe Method m=managedBean.getGetter(name, this, resource); Object result = null; try { - Class declaring=m.getDeclaringClass(); + Class declaring = m.getDeclaringClass(); // workaround for catalina weird mbeans - the declaring class is BaseModelMBean. // but this is the catalina class. if( declaring.isAssignableFrom(this.getClass()) ) { @@ -322,7 +322,7 @@ public class BaseModelMBean implements DynamicMBean, MBeanRegistration, ModelMBe } - static Class getAttributeClass(String signature) + static Class getAttributeClass(String signature) throws ReflectionException { if (signature.equals(Boolean.TYPE.getName())) @@ -467,7 +467,7 @@ public class BaseModelMBean implements DynamicMBean, MBeanRegistration, ModelMBe // Prepare and return our response, eating all exceptions String names[] = new String[attributes.size()]; int n = 0; - Iterator items = attributes.iterator(); + Iterator items = attributes.iterator(); while (items.hasNext()) { Attribute item = (Attribute) items.next(); names[n++] = item.getName(); diff --git a/java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java b/java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java index 31b54a74a..860e630c1 100644 --- a/java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java +++ b/java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java @@ -53,7 +53,8 @@ public class BaseNotificationBroadcaster implements NotificationBroadcaster { * The set of registered BaseNotificationBroadcasterEntry * entries. */ - protected ArrayList entries = new ArrayList(); + protected ArrayList entries = + new ArrayList(); // --------------------------------------------------------- Public Methods @@ -80,10 +81,10 @@ public class BaseNotificationBroadcaster implements NotificationBroadcaster { // Optimization to coalesce attribute name filters if (filter instanceof BaseAttributeFilter) { BaseAttributeFilter newFilter = (BaseAttributeFilter) filter; - Iterator items = entries.iterator(); + Iterator items = + entries.iterator(); while (items.hasNext()) { - BaseNotificationBroadcasterEntry item = - (BaseNotificationBroadcasterEntry) items.next(); + BaseNotificationBroadcasterEntry item = items.next(); if ((item.listener == listener) && (item.filter != null) && (item.filter instanceof BaseAttributeFilter) && @@ -137,10 +138,10 @@ public class BaseNotificationBroadcaster implements NotificationBroadcaster { throws ListenerNotFoundException { synchronized (entries) { - Iterator items = entries.iterator(); + Iterator items = + entries.iterator(); while (items.hasNext()) { - BaseNotificationBroadcasterEntry item = - (BaseNotificationBroadcasterEntry) items.next(); + BaseNotificationBroadcasterEntry item = items.next(); if (item.listener == listener) items.remove(); } @@ -200,10 +201,10 @@ public class BaseNotificationBroadcaster implements NotificationBroadcaster { public void sendNotification(Notification notification) { synchronized (entries) { - Iterator items = entries.iterator(); + Iterator items = + entries.iterator(); while (items.hasNext()) { - BaseNotificationBroadcasterEntry item = - (BaseNotificationBroadcasterEntry) items.next(); + BaseNotificationBroadcasterEntry item = items.next(); if ((item.filter != null) && (!item.filter.isNotificationEnabled(notification))) continue; diff --git a/java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java b/java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java index a08806f24..aecb64003 100644 --- a/java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java +++ b/java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java @@ -44,7 +44,7 @@ public class FixedNotificationFilter implements NotificationFilter { * The set of attribute names that are accepted by this filter. If this * list is empty, all attribute names are accepted. */ - private HashSet names = new HashSet(); + private HashSet names = new HashSet(); String namesA[]=null; /** @@ -64,7 +64,7 @@ public class FixedNotificationFilter implements NotificationFilter { */ public String[] getNames() { synchronized (names) { - return ((String[]) names.toArray(new String[names.size()])); + return names.toArray(new String[names.size()]); } } diff --git a/java/org/apache/tomcat/util/modeler/ManagedBean.java b/java/org/apache/tomcat/util/modeler/ManagedBean.java index 575c15234..05d3090b6 100644 --- a/java/org/apache/tomcat/util/modeler/ManagedBean.java +++ b/java/org/apache/tomcat/util/modeler/ManagedBean.java @@ -50,8 +50,8 @@ public class ManagedBean implements java.io.Serializable { private static final String BASE_MBEAN = "org.apache.tomcat.util.modeler.BaseModelMBean"; // ----------------------------------------------------- Instance Variables - static final Object[] NO_ARGS_PARAM=new Object[0]; - static final Class[] NO_ARGS_PARAM_SIG=new Class[0]; + static final Object[] NO_ARGS_PARAM = new Object[0]; + static final Class[] NO_ARGS_PARAM_SIG = new Class[0]; /** @@ -59,10 +59,12 @@ public class ManagedBean implements java.io.Serializable * to this ManagedBean instance. */ transient MBeanInfo info = null; - // Map - private Map attributes = new HashMap(); - //Map - private Map operations = new HashMap(); + + private Map attributes = + new HashMap(); + + private Map operations = + new HashMap(); protected String className = BASE_MBEAN; //protected ConstructorInfo constructors[] = new ConstructorInfo[0]; @@ -347,7 +349,7 @@ public class ManagedBean implements java.io.Serializable // Skip introspection mbean = new BaseModelMBean(); } else { - Class clazz = null; + Class clazz = null; Exception ex = null; try { clazz = Class.forName(getClassName()); @@ -484,7 +486,7 @@ public class ManagedBean implements java.io.Serializable Method m=null; // (Method)getAttMap.get( name ); if( m==null ) { - AttributeInfo attrInfo = (AttributeInfo)attributes.get(aname); + AttributeInfo attrInfo = attributes.get(aname); // Look up the actual operation to be used if (attrInfo == null) throw new AttributeNotFoundException(" Cannot find attribute " + aname + " for " + resource); @@ -526,7 +528,7 @@ public class ManagedBean implements java.io.Serializable Method m=null;//(Method)setAttMap.get( name ); if( m==null ) { - AttributeInfo attrInfo = (AttributeInfo)attributes.get(aname); + AttributeInfo attrInfo = attributes.get(aname); if (attrInfo == null) throw new AttributeNotFoundException(" Cannot find attribute " + aname); @@ -537,7 +539,8 @@ public class ManagedBean implements java.io.Serializable String argType=attrInfo.getType(); - Class signature[] = new Class[] { BaseModelMBean.getAttributeClass( argType ) }; + Class signature[] = + new Class[] { BaseModelMBean.getAttributeClass( argType ) }; Object object = null; NoSuchMethodException exception = null; @@ -582,7 +585,7 @@ public class ManagedBean implements java.io.Serializable // Acquire the ModelMBeanOperationInfo information for // the requested operation - OperationInfo opInfo = (OperationInfo)operations.get(aname); + OperationInfo opInfo = operations.get(aname); if (opInfo == null) throw new MBeanException(new ServiceNotFoundException( "Cannot find operation " + aname), @@ -590,7 +593,7 @@ public class ManagedBean implements java.io.Serializable // Prepare the signature required by Java reflection APIs // FIXME - should we use the signature from opInfo? - Class types[] = new Class[signature.length]; + Class types[] = new Class[signature.length]; for (int i = 0; i < signature.length; i++) { types[i] = BaseModelMBean.getAttributeClass(signature[i]); } diff --git a/java/org/apache/tomcat/util/modeler/Registry.java b/java/org/apache/tomcat/util/modeler/Registry.java index 5e95f1f00..f04b91fe7 100644 --- a/java/org/apache/tomcat/util/modeler/Registry.java +++ b/java/org/apache/tomcat/util/modeler/Registry.java @@ -82,7 +82,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { /** Will be used to isolate different apps and enhance security. */ - private static HashMap perLoaderRegistries=null; + private static HashMap perLoaderRegistries = null; /** * The registry instance created by our factory method the first time @@ -102,21 +102,24 @@ public class Registry implements RegistryMBean, MBeanRegistration { * The set of ManagedBean instances for the beans this registry * knows about, keyed by name. */ - private HashMap descriptors = new HashMap(); + private HashMap descriptors = + new HashMap(); /** List of managed byeans, keyed by class name */ - private HashMap descriptorsByClass = new HashMap(); + private HashMap descriptorsByClass = + new HashMap(); // map to avoid duplicated searching or loading descriptors - private HashMap searchedPaths=new HashMap(); + private HashMap searchedPaths=new HashMap(); private Object guard; // Id - small ints to use array access. No reset on stop() // Used for notifications - private Hashtable idDomains=new Hashtable(); - private Hashtable ids=new Hashtable(); + private Hashtable> idDomains = + new Hashtable>(); + private Hashtable ids = new Hashtable(); // ----------------------------------------------------------- Constructors @@ -153,7 +156,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { if( key==null ) key=Thread.currentThread().getContextClassLoader(); if( key != null ) { - localRegistry=(Registry)perLoaderRegistries.get(key); + localRegistry = perLoaderRegistries.get(key); if( localRegistry == null ) { localRegistry=new Registry(); // localRegistry.key=key; @@ -190,7 +193,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { */ public static void setUseContextClassLoader( boolean enable ) { if( enable ) { - perLoaderRegistries=new HashMap(); + perLoaderRegistries = new HashMap(); } } @@ -202,9 +205,9 @@ public class Registry implements RegistryMBean, MBeanRegistration { * @since 1.1 */ public void stop() { - descriptorsByClass = new HashMap(); - descriptors = new HashMap(); - searchedPaths=new HashMap(); + descriptorsByClass = new HashMap(); + descriptors = new HashMap(); + searchedPaths=new HashMap(); } /** @@ -222,7 +225,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { * * @since 1.1 */ - public List loadMBeans( Object source, ClassLoader cl ) + public List loadMBeans( Object source, ClassLoader cl ) throws Exception { return load("MbeansSource", source, null ); @@ -303,30 +306,22 @@ public class Registry implements RegistryMBean, MBeanRegistration { * @throws Exception * @since 1.1 */ - public void invoke( List mbeans, String operation, boolean failFirst ) - throws Exception - { + public void invoke(List mbeans, String operation, + boolean failFirst ) throws Exception { if( mbeans==null ) { return; } - Iterator itr=mbeans.iterator(); + Iterator itr = mbeans.iterator(); while(itr.hasNext()) { - Object current=itr.next(); - ObjectName oN=null; + ObjectName current = itr.next(); try { - if( current instanceof ObjectName) { - oN=(ObjectName)current; - } - if( current instanceof String ) { - oN=new ObjectName( (String)current ); - } - if( oN==null ) { + if(current == null) { continue; } - if( getMethodInfo(oN, operation) == null) { + if(getMethodInfo(current, operation) == null) { continue; } - getMBeanServer().invoke(oN, operation, + getMBeanServer().invoke(current, operation, new Object[] {}, new String[] {}); } catch( Exception t ) { @@ -350,21 +345,21 @@ public class Registry implements RegistryMBean, MBeanRegistration { if( domain==null) { domain=""; } - Hashtable domainTable=(Hashtable)idDomains.get( domain ); + Hashtable domainTable = idDomains.get(domain); if( domainTable == null ) { - domainTable=new Hashtable(); + domainTable = new Hashtable(); idDomains.put( domain, domainTable); } if( name==null ) { name=""; } - Integer i=(Integer)domainTable.get(name); + Integer i = domainTable.get(name); if( i!= null ) { return i.intValue(); } - int id[]=(int [])ids.get( domain ); + int id[] = ids.get(domain); if( id == null ) { id=new int[1]; ids.put( domain, id); @@ -403,9 +398,9 @@ public class Registry implements RegistryMBean, MBeanRegistration { */ public ManagedBean findManagedBean(String name) { // XXX Group ?? Use Group + Type - ManagedBean mb=((ManagedBean) descriptors.get(name)); + ManagedBean mb = descriptors.get(name); if( mb==null ) - mb=(ManagedBean)descriptorsByClass.get(name); + mb = descriptorsByClass.get(name); return mb; } @@ -416,7 +411,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { * @since 1.0 */ public String[] findManagedBeans() { - return ((String[]) descriptors.keySet().toArray(new String[0])); + return descriptors.keySet().toArray(new String[0]); } @@ -430,10 +425,10 @@ public class Registry implements RegistryMBean, MBeanRegistration { */ public String[] findManagedBeans(String group) { - ArrayList results = new ArrayList(); - Iterator items = descriptors.values().iterator(); + ArrayList results = new ArrayList(); + Iterator items = descriptors.values().iterator(); while (items.hasNext()) { - ManagedBean item = (ManagedBean) items.next(); + ManagedBean item = items.next(); if ((group == null) && (item.getGroup() == null)) { results.add(item.getName()); } else if (group.equals(item.getGroup())) { @@ -441,7 +436,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { } } String values[] = new String[results.size()]; - return ((String[]) results.toArray(values)); + return results.toArray(values); } @@ -589,7 +584,8 @@ public class Registry implements RegistryMBean, MBeanRegistration { if (server == null) { if( MBeanServerFactory.findMBeanServer(null).size() > 0 ) { - server=(MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0); + server = (MBeanServer) MBeanServerFactory.findMBeanServer( + null).get(0); if( log.isDebugEnabled() ) { log.debug("Using existing MBeanServer " + (System.currentTimeMillis() - t1 )); } @@ -605,9 +601,8 @@ public class Registry implements RegistryMBean, MBeanRegistration { /** Find or load metadata. */ - public ManagedBean findManagedBean(Object bean, Class beanClass, String type) - throws Exception - { + public ManagedBean findManagedBean(Object bean, Class beanClass, + String type) throws Exception { if( bean!=null && beanClass==null ) { beanClass=bean.getClass(); } @@ -707,9 +702,8 @@ public class Registry implements RegistryMBean, MBeanRegistration { * @throws Exception * @deprecated bad interface, mixing of metadata and mbeans */ - public List load( String sourceType, Object source, String param) - throws Exception - { + public List load( String sourceType, Object source, + String param) throws Exception { if( log.isTraceEnabled()) { log.trace("load " + source ); } @@ -739,7 +733,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { type=param; inputsource=source; } else if( source instanceof Class ) { - location=((Class)source).getName(); + location=((Class)source).getName(); type=param; inputsource=source; if( sourceType== null ) { @@ -751,7 +745,8 @@ public class Registry implements RegistryMBean, MBeanRegistration { sourceType="MbeansDescriptorsDigesterSource"; } ModelerSource ds=getModelerSource(sourceType); - List mbeans=ds.loadDescriptors(this, location, type, inputsource); + List mbeans = + ds.loadDescriptors(this, location, type, inputsource); return mbeans; } @@ -852,7 +847,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { return; } - /** Experimental. Will become private, some code may still use it + /**Experimental. Will become private, some code may still use it * * @param sourceType * @param source @@ -860,19 +855,9 @@ public class Registry implements RegistryMBean, MBeanRegistration { * @throws Exception * @deprecated */ - public void loadDescriptors( String sourceType, Object source, String param) - throws Exception - { - List mbeans=load( sourceType, source, param ); - if( mbeans == null) return; - - Iterator itr=mbeans.iterator(); - while( itr.hasNext() ) { - Object mb=itr.next(); - if( mb instanceof ManagedBean) { - addManagedBean((ManagedBean)mb); - } - } + public void loadDescriptors(String sourceType, Object source, String param) + throws Exception { + load(sourceType, source, param); } /** Lookup the component descriptor in the package and @@ -881,7 +866,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { * @param beanClass * @param type */ - private void findDescriptor( Class beanClass, String type ) { + private void findDescriptor(Class beanClass, String type) { if( type==null ) { type=beanClass.getName(); } @@ -918,7 +903,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { type="org.apache.tomcat.util.modeler.modules." + type; } - Class c=Class.forName( type ); + Class c = Class.forName(type); ModelerSource ds=(ModelerSource)c.newInstance(); return ds; } @@ -957,7 +942,7 @@ public class Registry implements RegistryMBean, MBeanRegistration { perLoaderRegistries.remove(loader); } - public ManagedBean findManagedBean(Class beanClass, String type) + public ManagedBean findManagedBean(Class beanClass, String type) throws Exception { return findManagedBean(null, beanClass, type); diff --git a/java/org/apache/tomcat/util/modeler/RegistryMBean.java b/java/org/apache/tomcat/util/modeler/RegistryMBean.java index 4b135c768..37e74eb36 100644 --- a/java/org/apache/tomcat/util/modeler/RegistryMBean.java +++ b/java/org/apache/tomcat/util/modeler/RegistryMBean.java @@ -21,6 +21,8 @@ package org.apache.tomcat.util.modeler; import java.util.List; +import javax.management.ObjectName; + /** * Interface for modeler MBeans. * @@ -53,7 +55,8 @@ public interface RegistryMBean { * * @since 1.1 */ - public List loadMBeans( Object source, ClassLoader cl ) throws Exception; + public List loadMBeans( Object source, ClassLoader cl ) + throws Exception; /** Invoke an operation on a set of mbeans. * @@ -63,7 +66,7 @@ public interface RegistryMBean { * errors * @throws Exception */ - public void invoke( List mbeans, String operation, boolean failFirst ) + public void invoke( List mbeans, String operation, boolean failFirst ) throws Exception; /** Register a bean by creating a modeler mbean and adding it to the diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java index b58e5b3ec..f108d9f30 100644 --- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java +++ b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java @@ -22,6 +22,8 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import javax.management.ObjectName; + import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.DomUtil; @@ -43,7 +45,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource String location; String type; Object source; - List mbeans=new ArrayList(); + List mbeans=new ArrayList(); public void setRegistry(Registry reg) { this.registry=reg; @@ -65,7 +67,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource this.source=source; } - public List loadDescriptors( Registry registry, String location, + public List loadDescriptors( Registry registry, String location, String type, Object source) throws Exception { @@ -289,9 +291,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource } // Add the completed managed bean info to the registry - //registry.addManagedBean(managed); - mbeans.add( managed ); - + registry.addManagedBean(managed); } long t2=System.currentTimeMillis(); diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java index 8133029fd..3c0221ecb 100644 --- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java +++ b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java @@ -21,9 +21,13 @@ package org.apache.tomcat.util.modeler.modules; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import javax.management.ObjectName; + import org.apache.tomcat.util.digester.Digester; +import org.apache.tomcat.util.modeler.ManagedBean; import org.apache.tomcat.util.modeler.Registry; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -37,7 +41,7 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource String location; String type; Object source; - List mbeans=new ArrayList(); + List mbeans = new ArrayList(); protected static Digester digester = null; protected static Digester createDigester(Registry registry) { @@ -200,10 +204,8 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource this.source=source; } - public List loadDescriptors( Registry registry, String location, - String type, Object source) - throws Exception - { + public List loadDescriptors( Registry registry, String location, + String type, Object source) throws Exception { setRegistry(registry); setLocation(location); setType(type); @@ -222,13 +224,14 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource if (digester == null) { digester = createDigester(registry); } + ArrayList loadedMbeans = new ArrayList(); synchronized (digester) { - + // Process the input file to configure our registry try { // Push our registry object onto the stack - digester.push(mbeans); + digester.push(loadedMbeans); digester.parse(stream); } catch (Exception e) { log.error("Error digesting Registry data", e); @@ -238,6 +241,9 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource } } - + Iterator iter = loadedMbeans.iterator(); + while (iter.hasNext()) { + registry.addManagedBean(iter.next()); + } } } diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java index f9331b9f0..94ed10fbe 100644 --- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java +++ b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java @@ -44,7 +44,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource String location; String type; Object source; - List mbeans=new ArrayList(); + List mbeans = new ArrayList(); public void setRegistry(Registry reg) { this.registry=reg; @@ -66,10 +66,8 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource this.source=source; } - public List loadDescriptors( Registry registry, String location, - String type, Object source) - throws Exception - { + public List loadDescriptors( Registry registry, String location, + String type, Object source) throws Exception { setRegistry(registry); setLocation(location); setType(type); @@ -81,11 +79,12 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource public void execute() throws Exception { if( registry==null ) registry=Registry.getRegistry(); try { - ManagedBean managed=createManagedBean(registry, null, (Class)source, type); + ManagedBean managed = createManagedBean(registry, null, + (Class)source, type); if( managed==null ) return; managed.setName( type ); - mbeans.add(managed); + registry.addManagedBean(managed); } catch( Exception ex ) { log.error( "Error reading descriptors ", ex); @@ -96,7 +95,8 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource // ------------ Implementation for non-declared introspection classes - static Hashtable specialMethods=new Hashtable(); + static Hashtable specialMethods = + new Hashtable(); static { specialMethods.put( "preDeregister", ""); specialMethods.put( "postDeregister", ""); @@ -106,7 +106,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource private static ObjectName objNameArray[]=new ObjectName[0]; // createMBean == registerClass + registerMBean - private static Class[] supportedTypes = new Class[] { + private static Class[] supportedTypes = new Class[] { Boolean.class, Boolean.TYPE, Byte.class, @@ -139,7 +139,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource * @param ret The class to check * @return boolean True if class is supported */ - private boolean supportedType(Class ret) { + private boolean supportedType(Class ret) { for (int i = 0; i < supportedTypes.length; i++) { if (ret == supportedTypes[i]) { return true; @@ -158,7 +158,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource * @param javaType The class to check * @return boolean True if the class is compatible. */ - protected boolean isBeanCompatible(Class javaType) { + protected boolean isBeanCompatible(Class javaType) { // Must be a non-primitive and non array if (javaType.isArray() || javaType.isPrimitive()) { return false; @@ -178,7 +178,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource } // Make sure superclass is compatible - Class superClass = javaType.getSuperclass(); + Class superClass = javaType.getSuperclass(); if (superClass != null && superClass != java.lang.Object.class && superClass != java.lang.Exception.class && @@ -200,10 +200,12 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource * @param setAttMap The settable attributes map * @param invokeAttMap The invokable attributes map */ - private void initMethods(Class realClass, + private void initMethods(Class realClass, Method methods[], - Hashtable attMap, Hashtable getAttMap, - Hashtable setAttMap, Hashtable invokeAttMap) + Hashtable attMap, + Hashtable getAttMap, + Hashtable setAttMap, + Hashtable invokeAttMap) { for (int j = 0; j < methods.length; ++j) { String name=methods[j].getName(); @@ -217,10 +219,10 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource } if( methods[j].getDeclaringClass() == Object.class ) continue; - Class params[]=methods[j].getParameterTypes(); + Class params[] = methods[j].getParameterTypes(); if( name.startsWith( "get" ) && params.length==0) { - Class ret=methods[j].getReturnType(); + Class ret = methods[j].getReturnType(); if( ! supportedType( ret ) ) { if( log.isDebugEnabled() ) log.debug("Unsupported type " + methods[j]); @@ -232,7 +234,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource // just a marker, we don't use the value attMap.put( name, methods[j] ); } else if( name.startsWith( "is" ) && params.length==0) { - Class ret=methods[j].getReturnType(); + Class ret = methods[j].getReturnType(); if( Boolean.TYPE != ret ) { if( log.isDebugEnabled() ) log.debug("Unsupported type " + methods[j] + " " + ret ); @@ -287,19 +289,19 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource * @return ManagedBean The create MBean */ public ManagedBean createManagedBean(Registry registry, String domain, - Class realClass, String type) + Class realClass, String type) { ManagedBean mbean= new ManagedBean(); Method methods[]=null; - Hashtable attMap=new Hashtable(); + Hashtable attMap = new Hashtable(); // key: attribute val: getter method - Hashtable getAttMap=new Hashtable(); + Hashtable getAttMap = new Hashtable(); // key: attribute val: setter method - Hashtable setAttMap=new Hashtable(); + Hashtable setAttMap = new Hashtable(); // key: operation val: invoke method - Hashtable invokeAttMap=new Hashtable(); + Hashtable invokeAttMap = new Hashtable(); methods = realClass.getMethods(); @@ -307,23 +309,23 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource try { - Enumeration en=attMap.keys(); + Enumeration en = attMap.keys(); while( en.hasMoreElements() ) { - String name=(String)en.nextElement(); + String name = en.nextElement(); AttributeInfo ai=new AttributeInfo(); ai.setName( name ); - Method gm=(Method)getAttMap.get(name); + Method gm = getAttMap.get(name); if( gm!=null ) { //ai.setGetMethodObj( gm ); ai.setGetMethod( gm.getName()); - Class t=gm.getReturnType(); + Class t=gm.getReturnType(); if( t!=null ) ai.setType( t.getName() ); } - Method sm=(Method)setAttMap.get(name); + Method sm = setAttMap.get(name); if( sm!=null ) { //ai.setSetMethodObj(sm); - Class t=sm.getParameterTypes()[0]; + Class t = sm.getParameterTypes()[0]; if( t!=null ) ai.setType( t.getName()); ai.setSetMethod( sm.getName()); @@ -341,14 +343,14 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource en=invokeAttMap.keys(); while( en.hasMoreElements() ) { - String name=(String)en.nextElement(); - Method m=(Method)invokeAttMap.get(name); + String name = en.nextElement(); + Method m = invokeAttMap.get(name); if( m!=null && name != null ) { OperationInfo op=new OperationInfo(); op.setName(name); op.setReturnType(m.getReturnType().getName()); op.setDescription("Introspected operation " + name); - Class parms[]=m.getParameterTypes(); + Class parms[] = m.getParameterTypes(); for(int i=0; i mbeans=new ArrayList(); public void setRegistry(Registry reg) { this.registry=reg; @@ -57,10 +59,8 @@ public class MbeansDescriptorsSerSource extends ModelerSource this.source=source; } - public List loadDescriptors( Registry registry, String location, - String type, Object source) - throws Exception - { + public List loadDescriptors( Registry registry, String location, + String type, Object source) throws Exception { setRegistry(registry); setLocation(location); setType(type); @@ -90,7 +90,7 @@ public class MbeansDescriptorsSerSource extends ModelerSource ManagedBean beans[]=(ManagedBean[])obj; // after all are read without error for( int i=0; i mbeans = new ArrayList(); static boolean loaderLoaded=false; private Document document; - private HashMap object2Node = new HashMap(); + private HashMap object2Node = + new HashMap(); long lastUpdate; long updateInterval=10000; // 10s @@ -98,14 +99,12 @@ public class MbeansSource extends ModelerSource implements MbeansSourceMBean /** Return the list of mbeans created by this source. * It can be used to implement runtime services. */ - public List getMBeans() { + public List getMBeans() { return mbeans; } - public List loadDescriptors( Registry registry, String location, - String type, Object source) - throws Exception - { + public List loadDescriptors(Registry registry, String location, + String type, Object source) throws Exception { setRegistry(registry); setLocation(location); setType(type); @@ -161,7 +160,7 @@ public class MbeansSource extends ModelerSource implements MbeansSourceMBean firstMbeanN=descriptorsN; } - MBeanServer server=(MBeanServer)Registry.getServer(); + MBeanServer server = Registry.getServer(); // XXX Not very clean... Just a workaround if( ! loaderLoaded ) { @@ -273,7 +272,7 @@ public class MbeansSource extends ModelerSource implements MbeansSourceMBean if( loading ) return; // nothing by default //log.info( "XXX UpdateField " + oname + " " + name + " " + value); - Node n=(Node)object2Node.get( oname ); + Node n = object2Node.get(oname); if( n == null ) { log.info( "Node not found " + oname ); return; diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java b/java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java index 3883118f2..5f4fd81f5 100644 --- a/java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java +++ b/java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java @@ -18,6 +18,8 @@ package org.apache.tomcat.util.modeler.modules; import java.util.List; +import javax.management.ObjectName; + /** * This mbean will load an extended mlet file ( similar in syntax with jboss ). @@ -38,7 +40,7 @@ public interface MbeansSourceMBean * * @return List of ObjectName */ - public List getMBeans(); + public List getMBeans(); /** Load the mbeans from the source. Called automatically on init() * diff --git a/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java b/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java index 7c9703083..77bada4fa 100644 --- a/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java +++ b/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java @@ -42,10 +42,8 @@ public class ModelerSource { * @param source Introspected object or some other source * @throws Exception */ - public List loadDescriptors( Registry registry, String location, - String type, Object source) - throws Exception - { + public List loadDescriptors( Registry registry, String location, + String type, Object source) throws Exception { // TODO return null; } -- 2.11.0