📄 jmxmbeanserver.java
字号:
/* * @(#)JmxMBeanServer.java 1.75 05/12/29 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.jmx.mbeanserver;// java importimport java.util.Iterator;import java.util.ArrayList;import java.util.Set;import java.util.HashSet;import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Constructor;import java.io.OptionalDataException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.IOException ;import java.security.AccessController;import java.security.Permission;import java.security.PrivilegedExceptionAction;// RI importimport javax.management.MBeanPermission;import javax.management.DynamicMBean;import javax.management.AttributeNotFoundException;import javax.management.MBeanException; import javax.management.ReflectionException;import javax.management.MBeanAttributeInfo;import javax.management.MBeanInfo;import javax.management.QueryExp;import javax.management.NotificationListener;import javax.management.NotificationFilter;import javax.management.ListenerNotFoundException;import javax.management.IntrospectionException;import javax.management.OperationsException;import javax.management.MBeanNotificationInfo;import javax.management.JMRuntimeException;import javax.management.InstanceNotFoundException;import javax.management.NotCompliantMBeanException;import javax.management.MBeanRegistrationException;import javax.management.InstanceAlreadyExistsException;import javax.management.InvalidAttributeValueException;import javax.management.ObjectName;import javax.management.ObjectInstance;import javax.management.Attribute;import javax.management.AttributeList;import javax.management.RuntimeOperationsException;import javax.management.MBeanServer; import javax.management.MBeanServerDelegate; import javax.management.loading.ClassLoaderRepository;import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;import com.sun.jmx.interceptor.MBeanServerInterceptor;import com.sun.jmx.defaults.ServiceName;import com.sun.jmx.trace.Trace;/** * This is the base class for MBean manipulation on the agent side. It * contains the methods necessary for the creation, registration, and * deletion of MBeans as well as the access methods for registered MBeans. * This is the core component of the JMX infrastructure. * <P> * Every MBean which is added to the MBean server becomes manageable: * its attributes and operations become remotely accessible through * the connectors/adaptors connected to that MBean server. * A Java object cannot be registered in the MBean server unless it is a * JMX compliant MBean. * <P> * When an MBean is registered or unregistered in the MBean server an * {@link javax.management.MBeanServerNotification MBeanServerNotification} * Notification is emitted. To register an object as listener to * MBeanServerNotifications you should call the MBean server method * {@link #addNotificationListener addNotificationListener} with * the <CODE>ObjectName</CODE> of the * {@link javax.management.MBeanServerDelegate MBeanServerDelegate}. * This <CODE>ObjectName</CODE> is: * <BR> * <CODE>JMImplementation:type=MBeanServerDelegate</CODE>. * * @since 1.5 */public final class JmxMBeanServer implements SunJmxMBeanServer { /** The name of this class to be used for tracing */ private static final String dbgTag = "MBeanServer"; private final MBeanInstantiator instantiator; private final SecureClassLoaderRepository secureClr; /** true if interceptors are enabled **/ private final boolean interceptorsEnabled; /** Revisit: transient ??? **/ private final transient MBeanServer outerShell; /** Revisit: transient ??? **/ private transient MBeanServerInterceptor mbsInterceptor = null; /** Revisit: transient ??? **/ /** The MBeanServerDelegate object representing the MBean Server */ private final transient MBeanServerDelegate mBeanServerDelegateObject; /** * <b>Package:</b> Creates an MBeanServer with the * specified default domain name, outer interface, and delegate. * <p>The default domain name is used as the domain part in the ObjectName * of MBeans if no domain is specified by the user. * <ul><b>Note:</b>Using this constructor directly is strongly * discouraged. You should use * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)} * or * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)} * instead. * <p> * By default, {@link MBeanServerInterceptor} are disabled. Use * {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them. * </ul> * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @exception IllegalArgumentException if the instantiator is null. */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate) { this(domain,outer,delegate,null,false); } /** * <b>Package:</b> Creates an MBeanServer with the * specified default domain name, outer interface, and delegate. * <p>The default domain name is used as the domain part in the ObjectName * of MBeans if no domain is specified by the user. * <ul><b>Note:</b>Using this constructor directly is strongly * discouraged. You should use * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)} * or * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)} * instead. * </ul> * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @param interceptors If <code>true</code>, * {@link MBeanServerInterceptor} will be enabled (default is * <code>false</code>) * Note: this parameter is not taken into account by this * implementation - the default value <code>false</code> is * always used. * @exception IllegalArgumentException if the instantiator is null. */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate, boolean interceptors) { this(domain,outer,delegate,null,false); } /** * <b>Package:</b> Creates an MBeanServer. * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @param instantiator The MBeanInstantiator that will be used to * instantiate MBeans and take care of class loading issues. * @param metadata The MetaData object that will be used by the * MBean server in order to invoke the MBean interface of * the registered MBeans. * @param interceptors If <code>true</code>, * {@link MBeanServerInterceptor} will be enabled (default is * <code>false</code>). */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate, MBeanInstantiator instantiator, boolean interceptors) { if (instantiator == null) { final ModifiableClassLoaderRepository clr = new ClassLoaderRepositorySupport(); instantiator = new MBeanInstantiator(clr); } this.secureClr = new SecureClassLoaderRepository(instantiator.getClassLoaderRepository()); if (delegate == null) delegate = new MBeanServerDelegateImpl(); if (outer == null) outer = this; this.instantiator = instantiator; this.mBeanServerDelegateObject = delegate; this.outerShell = outer; final Repository repository = new Repository(domain); this.mbsInterceptor = new DefaultMBeanServerInterceptor(outer, delegate, instantiator, repository); this.interceptorsEnabled = interceptors; initialize(); } /** * Tell whether {@link MBeanServerInterceptor}s are enabled on this * object. * @return <code>true</code> if {@link MBeanServerInterceptor}s are * enabled. * @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean) **/ public boolean interceptorsEnabled() { return interceptorsEnabled; } /** * Return the MBeanInstantiator associated to this MBeanServer. * @exception UnsupportedOperationException if * {@link MBeanServerInterceptor}s * are not enabled on this object. * @see #interceptorsEnabled **/ public MBeanInstantiator getMBeanInstantiator() { if (interceptorsEnabled) return instantiator; else throw new UnsupportedOperationException( "MBeanServerInterceptors are disabled."); } /** * Instantiates and registers an MBean in the MBean server. * The MBean server will use its * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository} * to load the class of the MBean. * An object name is associated to the MBean. * If the object name given is null, the MBean can automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name of the newly * instantiated MBean. * * @exception ReflectionException Wraps an * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> that occurred * when trying to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has thrown * an exception. * @exception NotCompliantMBeanException This class is not a JMX * compliant MBean. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: * The className passed in parameter is null, the * <CODE>ObjectName</CODE> passed in parameter contains a pattern * or no <CODE>ObjectName</CODE> is specified for the MBean. * */ public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException { return mbsInterceptor.createMBean(className, cloneObjectName(name), (Object[]) null, (String[]) null); } /** * Instantiates and registers an MBean in the MBean server. * The class loader to be used is identified by its object name. * An object name is associated to the MBean. * If the object name of the loader is null, the ClassLoader that * loaded the MBean server will be used. * If the MBean's object name given is null, the MBean can
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -