User: squirest Date: 02/02/25 18:03:01 Modified: src/main/org/jboss/mx/server MBeanServerImpl.java Log: moved and removed stuff. new items will go into capability until a better home can be found Revision Changes Path 1.18 +94 -87 jmx/src/main/org/jboss/mx/server/MBeanServerImpl.java Index: MBeanServerImpl.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/server/MBeanServerImpl.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- MBeanServerImpl.java 23 Feb 2002 16:10:02 -0000 1.17 +++ MBeanServerImpl.java 26 Feb 2002 02:03:00 -0000 1.18 @@ -6,19 +6,13 @@ */ package org.jboss.mx.server; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.InvocationTargetException; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; +import org.jboss.mx.loading.LoaderRepository; +import org.jboss.mx.logging.Logger; +import org.jboss.mx.metadata.MBeanCapability; +import org.jboss.mx.capability.DispatcherFactory; +import org.jboss.mx.server.registry.BasicMBeanRegistry; +import org.jboss.mx.server.registry.MBeanEntry; +import org.jboss.mx.server.registry.MBeanRegistry; import javax.management.Attribute; import javax.management.AttributeList; @@ -29,7 +23,6 @@ import javax.management.IntrospectionException; import javax.management.InvalidAttributeValueException; import javax.management.ListenerNotFoundException; -import javax.management.MalformedObjectNameException; import javax.management.MBeanException; import javax.management.MBeanInfo; import javax.management.MBeanRegistration; @@ -37,12 +30,13 @@ import javax.management.MBeanServer; import javax.management.MBeanServerDelegate; import javax.management.MBeanServerNotification; +import javax.management.MalformedObjectNameException; import javax.management.NotCompliantMBeanException; import javax.management.NotificationBroadcaster; -import javax.management.NotificationListener; import javax.management.NotificationFilter; -import javax.management.ObjectName; +import javax.management.NotificationListener; import javax.management.ObjectInstance; +import javax.management.ObjectName; import javax.management.OperationsException; import javax.management.QueryExp; import javax.management.ReflectionException; @@ -50,15 +44,15 @@ import javax.management.RuntimeMBeanException; import javax.management.RuntimeOperationsException; import javax.management.loading.DefaultLoaderRepository; - -import org.jboss.mx.capability.MBeanCapability; -import org.jboss.mx.interceptor.MBeanInvoker; -import org.jboss.mx.interceptor.MBeanTarget; -import org.jboss.mx.loading.LoaderRepository; -import org.jboss.mx.logging.Logger; -import org.jboss.mx.server.registry.BasicMBeanRegistry; -import org.jboss.mx.server.registry.MBeanEntry; -import org.jboss.mx.server.registry.MBeanRegistry; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; /** @@ -90,7 +84,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>. * @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>. - * @version $Revision: 1.17 $ + * @version $Revision: 1.18 $ */ public class MBeanServerImpl implements MBeanServer, ServerConstants @@ -108,32 +102,32 @@ private static final String[] NOSIG = new String[0]; // Attributes ---------------------------------------------------- - + /** - * Sequence number for the MBean server registration notifications. + * Sequence number for the MBean server registration notifications. */ protected long registrationNotificationSequence = 1; - + /** * Sequence number for the MBean server unregistration notifications. */ protected long unregistrationNotificationSequence = 1; - + /** * Default domain name ({@link ServerConstants#DEFAULT_DOMAIN DEFAULT_DOMAIN}) used by this server implementation. */ protected String defaultDomain = DEFAULT_DOMAIN; - + /** * Registry used by this server to map MBean object names to resource references. */ protected MBeanRegistry registry = null; - + /** * Direct reference to the mandatory MBean server delegate MBean. */ protected MBeanServerDelegate delegate = null; - + /** * Class loader repository for this server. The implementation class is retrieved via * {@link LoaderRepository#getDefaultLoaderRepository} call. @@ -167,7 +161,7 @@ try { - registerMBean(delegate, new ObjectName(MBEAN_SERVER_DELEGATE), + registerMBean(delegate, new ObjectName(MBEAN_SERVER_DELEGATE), null, JMImplementation); } catch (MalformedObjectNameException e) @@ -250,8 +244,8 @@ } public ObjectInstance registerMBean(Object object, ObjectName name) - throws InstanceAlreadyExistsException, - MBeanRegistrationException, + throws InstanceAlreadyExistsException, + MBeanRegistrationException, NotCompliantMBeanException { return registerMBean(object, name, null, null); @@ -264,7 +258,7 @@ if (name.getDomain().equals(JMImplementation)) throw new RuntimeOperationsException(new IllegalArgumentException( "Not allowed to unregister: " + name.toString())); - + MBeanEntry entry = registry.get(name); ClassLoader newTCL = entry.getClassLoader(); Object resource = entry.getResourceInstance(); @@ -323,7 +317,7 @@ if (!isRegistered(name)) throw new InstanceNotFoundException(name + " not registered."); - return new ServerObjectInstance(qualifyName(name), + return new ServerObjectInstance(qualifyName(name), registry.get(name).getResourceClassName(), delegate.getMBeanServerId()); } @@ -343,7 +337,7 @@ MBeanEntry entry = (MBeanEntry) iterator.next(); ObjectName objectName = entry.getObjectName(); if (queryMBean(objectName, query) == true) - result.add(new ServerObjectInstance(objectName, + result.add(new ServerObjectInstance(objectName, entry.getResourceClassName(), delegate.getMBeanServerId())); } @@ -383,15 +377,15 @@ } public Object getAttribute(ObjectName name, String attribute) - throws MBeanException, - AttributeNotFoundException, - InstanceNotFoundException, + throws MBeanException, + AttributeNotFoundException, + InstanceNotFoundException, ReflectionException { MBeanEntry entry = registry.get(name); ClassLoader newTCL = entry.getClassLoader(); DynamicMBean mbean = entry.getMBean(); - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -409,13 +403,13 @@ } public AttributeList getAttributes(ObjectName name, String[] attributes) - throws InstanceNotFoundException, + throws InstanceNotFoundException, ReflectionException { MBeanEntry entry = registry.get(name); ClassLoader newTCL = entry.getClassLoader(); DynamicMBean mbean = entry.getMBean(); - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -438,7 +432,7 @@ MBeanEntry entry = registry.get(name); ClassLoader newTCL = entry.getClassLoader(); DynamicMBean mbean = entry.getMBean(); - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -461,7 +455,7 @@ MBeanEntry entry = registry.get(name); ClassLoader newTCL = entry.getClassLoader(); DynamicMBean mbean = entry.getMBean(); - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -484,7 +478,7 @@ MBeanEntry entry = registry.get(name); ClassLoader newTCL = entry.getClassLoader(); DynamicMBean mbean = entry.getMBean(); - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -506,7 +500,7 @@ MBeanEntry entry = registry.get(name); ClassLoader newTCL = entry.getClassLoader(); DynamicMBean mbean = entry.getMBean(); - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -544,7 +538,7 @@ { throw new RuntimeOperationsException(e, "MBean " + name + " does not implement the NotificationBroadcaster interface."); } - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -575,7 +569,7 @@ { throw new RuntimeOperationsException(e, "MBean " + listener + " is not a notification listener or " + name + " does not implement notification broadcaster interface."); } - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -606,7 +600,7 @@ { throw new RuntimeOperationsException(e, "MBean " + name + " does not implement the NotificationBroadcaster interface."); } - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -637,7 +631,7 @@ { throw new RuntimeOperationsException(e, "MBean " + name + " does not implement the NotificationBroadcaster interface."); } - + Thread thread = Thread.currentThread(); ClassLoader oldTCL = thread.getContextClassLoader(); try @@ -724,14 +718,14 @@ * thread's context classloader for the duration of this method. * * @param className the class name of the object to instantiate - * @param cl the thread classloader, pass null to use the + * @param cl the thread classloader, pass null to use the * DefaultLoaderRepository * @param param the parameters for the constructor * @param signature the signature of the constructor * @exception ReflectionException wraps a ClassCastException or * any Exception trying to invoke the constructor * @expeption MBeanException wraps any exception thrown by the constructor - * @exception RuntimeOperationsException Wraps an IllegalArgument for a + * @exception RuntimeOperationsException Wraps an IllegalArgument for a * null className */ protected Object instantiate(String className, ClassLoader cl, Object[] params, String[] signature) throws ReflectionException, MBeanException @@ -753,7 +747,7 @@ } else clazz = DefaultLoaderRepository.loadClass(className); - + Class[] sign = new Class[signature.length]; for (int i = 0; i < signature.length; ++i) { @@ -776,9 +770,9 @@ catch (Throwable t) { handleInstantiateExceptions(t, className); - + log.error("Unhandled exception instantiating class: " + className, t); - + return null; } finally @@ -795,37 +789,37 @@ { if (t instanceof ClassNotFoundException) throw new ReflectionException((Exception)t, "Class not found: " + className); - + else if (t instanceof InstantiationException) throw new ReflectionException((Exception)t, "Cannot instantiate with no-args constructor: " + className); - + else if (t instanceof IllegalAccessException) throw new ReflectionException((Exception)t, "Illegal access to default constructor: " + className); - + else if (t instanceof NoSuchMethodException) throw new ReflectionException((Exception)t, className + " does not have a public no args constructor."); - + else if (t instanceof SecurityException) throw new ReflectionException((Exception)t, "Can't access default constructor for " + className + ": " + t.toString()); - + else if (t instanceof InvocationTargetException) { Throwable root = ((InvocationTargetException)t).getTargetException(); - + if (root instanceof RuntimeException) throw new RuntimeMBeanException((RuntimeException)root, className + " constructor has thrown an exception: " + root.toString()); else if (root instanceof Error) throw new RuntimeErrorException((Error)root, className + " constructor has thrown an error: " + root.toString()); else if (root instanceof Exception) throw new MBeanException((Exception)root, className + " constructor has thrown an exception: " + root.toString()); - + throw new Error("Something went wrong with handling the exception from " + className + " default constructor."); } - + else if (t instanceof ExceptionInInitializerError) { Throwable root = ((ExceptionInInitializerError)t).getException(); - + // the root cause can be only a runtime exception if (root instanceof RuntimeException) throw new RuntimeMBeanException((RuntimeException)root, "Exception in class " + className + " static initializer: " + root.toString()); @@ -833,24 +827,24 @@ // shouldn't get here throw new Error("ERROR: it turns out the root cause is not always a runtime exception!"); } - + else if (t instanceof IllegalArgumentException) { // if mismatch between constructor instance args and supplied args -- shouldn't happen throw new Error("Error in the server: mismatch between expected constructor arguments and supplied arguments."); } - + else if (t instanceof Error) { throw new RuntimeErrorException((Error)t, "instantiating " + className + " failed: " + t.toString()); - } - } + } + } /** * Register an MBean<p> * - * Pass {@link JMImplementation} in the magic token to get access to the + * Pass {@link JMImplementation} in the magic token to get access to the * reserved domain<p> * * The classloader is used as the thread context classloader during @@ -860,12 +854,12 @@ * @param name the object name to register * @param loaderName the object name of a class loader also used as * as the MBeans TCL - * @param magicToken used to get access to the + * @param magicToken used to get access to the * @exception InstanceAlreadyExistsException when already registered * @exception MBeanRegistrationException when * preRegister(MBeanServer, ObjectName) throws an exception * @exception NotCompliantMBeanException when the object is not an MBean - * @exception RuntimeOperationException containing an + * @exception RuntimeOperationException containing an * IllegalArgumentException for another problem with the name * or a null object */ @@ -890,7 +884,7 @@ /** * Register an MBean<p> * - * Pass {@link JMImplementation} in the magic token to get access to the + * Pass {@link JMImplementation} in the magic token to get access to the * reserved domain<p> * * The classloader is used as the thread context classloader during @@ -901,19 +895,19 @@ * @param object the mbean to register * @param name the object name to register * @param cl the thread classloader, pass null for the current one - * @param magicToken used to get access to the + * @param magicToken used to get access to the * @exception InstanceAlreadyExistsException when already registered * @exception MBeanRegistrationException when * preRegister(MBeanServer, ObjectName) throws an exception * @exception NotCompliantMBeanException when the object is not an MBean - * @exception RuntimeOperationException containing an + * @exception RuntimeOperationException containing an * IllegalArgumentException for another problem with the name * or a null object */ - protected ObjectInstance registerMBean(Object object, ObjectName name, + protected ObjectInstance registerMBean(Object object, ObjectName name, ClassLoader cl, String magicToken) - throws InstanceAlreadyExistsException, - MBeanRegistrationException, + throws InstanceAlreadyExistsException, + MBeanRegistrationException, NotCompliantMBeanException { boolean registrationDone = true; @@ -938,7 +932,11 @@ MBeanCapability mbcap = MBeanCapability.of(object.getClass()); // Does the bean require registration processing? - MBeanRegistration registrationInterface = mbcap.getMBeanRegistration(object); + MBeanRegistration registrationInterface = null; + if (object instanceof MBeanRegistration) + { + registrationInterface = (MBeanRegistration) object; + } try { @@ -971,8 +969,17 @@ try { // Register the mbean - MBeanTarget target = new MBeanTarget(mbcap.getMBean(object)); - MBeanInvoker invoker = new MBeanInvoker(target); + + DynamicMBean invoker = null; + if (mbcap.getMBeanType() == MBeanCapability.STANDARD_MBEAN) + { + invoker = DispatcherFactory.create(mbcap.getStandardMBeanInfo(), object); + } + else + { + invoker = DispatcherFactory.create((DynamicMBean)object); + } + MBeanEntry entry = new MBeanEntry(regName, invoker, object, mbeanCL); registry.add(entry); @@ -1073,7 +1080,7 @@ * @param magicToken used to get access to the reserved domain * @return the original name or the name prepended with the default domain * if no domain is specified. - * @exception RuntimeOperationException containing an + * @exception RuntimeOperationException containing an * IllegalArgumentException for a problem with the name */ private final ObjectName validateAndQualifyName(ObjectName name, @@ -1088,7 +1095,7 @@ new IllegalArgumentException("Object name is a pattern:" + name)); // Check for reserved domain - if (magicToken != JMImplementation && + if (magicToken != JMImplementation && result.getDomain().equals(JMImplementation)) throw new RuntimeOperationsException(new IllegalArgumentException( "Domain " + JMImplementation + " is reserved")); @@ -1110,7 +1117,7 @@ * @param name the name to qualify * @return the original name or the name prepended with the default domain * if no domain is specified. - * @exception RuntimeOperationException containing an + * @exception RuntimeOperationException containing an * IllegalArgumentException when there is a problem */ private final ObjectName qualifyName(ObjectName name) @@ -1121,7 +1128,7 @@ try { if (name.getDomain().length() == 0) - return new ObjectName(defaultDomain + ":" + + return new ObjectName(defaultDomain + ":" + name.getCanonicalKeyPropertyListString()); else return name;
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development