715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync/*
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync *
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * This code is free software; you can redistribute it and/or modify it
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * under the terms of the GNU General Public License version 2 only, as
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * published by the Free Software Foundation. Oracle designates this
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * particular file as subject to the "Classpath" exception as provided
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * by Oracle in the LICENSE file that accompanied this code.
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync *
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * This code is distributed in the hope that it will be useful, but WITHOUT
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c0b6af690ad705bddfa87c643b89770a7a0aaf5avboxsync * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * version 2 for more details (a copy is included in the LICENSE file that
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * accompanied this code).
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync *
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * You should have received a copy of the GNU General Public License version
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * 2 along with this work; if not, write to the Free Software Foundation,
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync *
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * or visit www.oracle.com if you need additional information or have any
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync * questions.
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync */
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncpackage javax.management;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport static com.sun.jmx.defaults.JmxProperties.MISC_LOGGER;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport com.sun.jmx.mbeanserver.DescriptorCache;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport com.sun.jmx.mbeanserver.Introspector;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport com.sun.jmx.mbeanserver.MBeanSupport;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport com.sun.jmx.mbeanserver.MXBeanSupport;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport com.sun.jmx.mbeanserver.StandardMBeanSupport;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport com.sun.jmx.mbeanserver.Util;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsync
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport java.security.AccessController;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport java.security.PrivilegedAction;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport java.util.HashMap;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport java.util.Map;
7674ee2f976dc48f8777b0e4aa1e0894e4b48a87vboxsyncimport java.util.WeakHashMap;
7674ee2f976dc48f8777b0e4aa1e0894e4b48a87vboxsyncimport java.util.logging.Level;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport javax.management.openmbean.OpenMBeanAttributeInfo;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport javax.management.openmbean.OpenMBeanAttributeInfoSupport;
7674ee2f976dc48f8777b0e4aa1e0894e4b48a87vboxsyncimport javax.management.openmbean.OpenMBeanConstructorInfo;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport javax.management.openmbean.OpenMBeanConstructorInfoSupport;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport javax.management.openmbean.OpenMBeanOperationInfo;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport javax.management.openmbean.OpenMBeanOperationInfoSupport;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport javax.management.openmbean.OpenMBeanParameterInfo;
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncimport javax.management.openmbean.OpenMBeanParameterInfoSupport;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
0e9bee76f5b28d974b91a2a66c61a36751d4a2c7vboxsync/**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>An MBean whose management interface is determined by reflection
0e9bee76f5b28d974b91a2a66c61a36751d4a2c7vboxsync * on a Java interface.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
0e9bee76f5b28d974b91a2a66c61a36751d4a2c7vboxsync * <p>This class brings more flexibility to the notion of Management
34edf41b7b7cb5219f0ce1b172e131ae7520ae83vboxsync * Interface in the use of Standard MBeans. Straightforward use of
34edf41b7b7cb5219f0ce1b172e131ae7520ae83vboxsync * the patterns for Standard MBeans described in the JMX Specification
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * means that there is a fixed relationship between the implementation
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * class of an MBean and its management interface (i.e., if the
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * implementation class is Thing, the management interface must be
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * ThingMBean). This class makes it possible to keep the convenience
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * of specifying the management interface with a Java interface,
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * without requiring that there be any naming relationship between the
34edf41b7b7cb5219f0ce1b172e131ae7520ae83vboxsync * implementation and interface classes.</p>
34edf41b7b7cb5219f0ce1b172e131ae7520ae83vboxsync *
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * <p>By making a DynamicMBean out of an MBean, this class makes
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * it possible to select any interface implemented by the MBean as its
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * management interface, provided that it complies with JMX patterns
eda35f91dbe2b4e221daaab631ef5eb225224185vboxsync * (i.e., attributes defined by getter/setter etc...).</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
0e9bee76f5b28d974b91a2a66c61a36751d4a2c7vboxsync * <p> This class also provides hooks that make it possible to supply
1d9b8ac46277d5cbab832794c5cfcce1e0521873vboxsync * custom descriptions and names for the {@link MBeanInfo} returned by
1d9b8ac46277d5cbab832794c5cfcce1e0521873vboxsync * the DynamicMBean interface.</p>
9454ea53d45685cd1eab5d21376ae7921b93242avboxsync *
9454ea53d45685cd1eab5d21376ae7921b93242avboxsync * <p>Using this class, an MBean can be created with any
af204635b63db99d98ba8dfcf4b952708bfe2ac5vboxsync * implementation class name <i>Impl</i> and with a management
af204635b63db99d98ba8dfcf4b952708bfe2ac5vboxsync * interface defined (as for current Standard MBeans) by any interface
9454ea53d45685cd1eab5d21376ae7921b93242avboxsync * <i>Intf</i>, in one of two general ways:</p>
9454ea53d45685cd1eab5d21376ae7921b93242avboxsync *
af204635b63db99d98ba8dfcf4b952708bfe2ac5vboxsync * <ul>
af204635b63db99d98ba8dfcf4b952708bfe2ac5vboxsync *
dda81d519b6d284ba60a7544bc74b850c8ff0d7avboxsync * <li>Using the public constructor
dda81d519b6d284ba60a7544bc74b850c8ff0d7avboxsync * {@link #StandardMBean(java.lang.Object, java.lang.Class, boolean)
dda81d519b6d284ba60a7544bc74b850c8ff0d7avboxsync * StandardMBean(impl,interface)}:
dda81d519b6d284ba60a7544bc74b850c8ff0d7avboxsync * <pre>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBeanServer mbs;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * ...
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Impl impl = new Impl(...);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * StandardMBean mbean = new StandardMBean(impl, Intf.class, false);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * mbs.registerMBean(mbean, objectName);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * </pre></li>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <li>Subclassing StandardMBean:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <pre>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * public class Impl extends StandardMBean implements Intf {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * public Impl() {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * super(Intf.class, false);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * // implement methods of Intf
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * [...]
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBeanServer mbs;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * ....
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Impl impl = new Impl();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * mbs.registerMBean(impl, objectName);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * </pre></li>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * </ul>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>In either case, the class <i>Impl</i> must implement the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * interface <i>Intf</i>.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Standard MBeans based on the naming relationship between
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * implementation and interface classes are of course still
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * available.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>This class may also be used to construct MXBeans. The usage
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * is exactly the same as for Standard MBeans except that in the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * examples above, the {@code false} parameter to the constructor or
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@code super(...)} invocation is instead {@code true}.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @since 1.5
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync */
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsyncpublic class StandardMBean implements DynamicMBean, MBeanRegistration {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private final static DescriptorCache descriptors =
c46e2b58f1dbcc439834b260c799b3d3027150e1vboxsync DescriptorCache.getInstance(JMX.proof);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * The DynamicMBean that wraps the MXBean or Standard MBean implementation.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private volatile MBeanSupport<?> mbean;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * The cached MBeanInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private volatile MBeanInfo cachedMBeanInfo;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Make a DynamicMBean out of <var>implementation</var>, using the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * specified <var>mbeanInterface</var> class.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param implementation The implementation of this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * If <code>null</code>, and null implementation is allowed,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * then the implementation is assumed to be <var>this</var>.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param mbeanInterface The Management Interface exported by this
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBean's implementation. If <code>null</code>, then this
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * object will use standard JMX design pattern to determine
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * the management interface associated with the given
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * implementation.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param nullImplementationAllowed <code>true</code> if a null
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * implementation is allowed. If null implementation is allowed,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * and a null implementation is passed, then the implementation
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * is assumed to be <var>this</var>.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @exception IllegalArgumentException if the given
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>implementation</var> is null, and null is not allowed.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private <T> void construct(T implementation, Class<T> mbeanInterface,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync boolean nullImplementationAllowed,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync boolean isMXBean)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync throws NotCompliantMBeanException {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (implementation == null) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // Have to use (T)this rather than mbeanInterface.cast(this)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // because mbeanInterface might be null.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (nullImplementationAllowed)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync implementation = Util.<T>cast(this);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync else throw new IllegalArgumentException("implementation is null");
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (isMXBean) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (mbeanInterface == null) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync mbeanInterface = Util.cast(Introspector.getMXBeanInterface(
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync implementation.getClass()));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync this.mbean = new MXBeanSupport(implementation, mbeanInterface);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (mbeanInterface == null) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync mbeanInterface = Util.cast(Introspector.getStandardMBeanInterface(
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync implementation.getClass()));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync this.mbean =
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync new StandardMBeanSupport(implementation, mbeanInterface);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Make a DynamicMBean out of the object
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>implementation</var>, using the specified
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>mbeanInterface</var> class.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param implementation The implementation of this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param mbeanInterface The Management Interface exported by this
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBean's implementation. If <code>null</code>, then this
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * object will use standard JMX design pattern to determine
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * the management interface associated with the given
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * implementation.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param <T> Allows the compiler to check
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * that {@code implementation} does indeed implement the class
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * described by {@code mbeanInterface}. The compiler can only
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * check this if {@code mbeanInterface} is a class literal such
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * as {@code MyMBean.class}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @exception IllegalArgumentException if the given
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>implementation</var> is null.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @exception NotCompliantMBeanException if the <var>mbeanInterface</var>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * does not follow JMX design patterns for Management Interfaces, or
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * if the given <var>implementation</var> does not implement the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * specified interface.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public <T> StandardMBean(T implementation, Class<T> mbeanInterface)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync throws NotCompliantMBeanException {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync construct(implementation, mbeanInterface, false, false);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Make a DynamicMBean out of <var>this</var>, using the specified
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>mbeanInterface</var> class.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Calls {@link #StandardMBean(java.lang.Object, java.lang.Class)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * this(this,mbeanInterface)}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * This constructor is reserved to subclasses.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param mbeanInterface The Management Interface exported by this
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @exception NotCompliantMBeanException if the <var>mbeanInterface</var>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * does not follow JMX design patterns for Management Interfaces, or
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * if <var>this</var> does not implement the specified interface.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected StandardMBean(Class<?> mbeanInterface)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync throws NotCompliantMBeanException {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync construct(null, mbeanInterface, true, false);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Make a DynamicMBean out of the object
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>implementation</var>, using the specified
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>mbeanInterface</var> class, and choosing whether the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * resultant MBean is an MXBean. This constructor can be used
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * to make either Standard MBeans or MXBeans. Unlike the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * constructor {@link #StandardMBean(Object, Class)}, it
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * does not throw NotCompliantMBeanException.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param implementation The implementation of this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param mbeanInterface The Management Interface exported by this
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBean's implementation. If <code>null</code>, then this
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * object will use standard JMX design pattern to determine
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * the management interface associated with the given
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * implementation.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param isMXBean If true, the {@code mbeanInterface} parameter
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * names an MXBean interface and the resultant MBean is an MXBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param <T> Allows the compiler to check
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * that {@code implementation} does indeed implement the class
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * described by {@code mbeanInterface}. The compiler can only
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * check this if {@code mbeanInterface} is a class literal such
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * as {@code MyMBean.class}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @exception IllegalArgumentException if the given
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>implementation</var> is null, or if the <var>mbeanInterface</var>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * does not follow JMX design patterns for Management Interfaces, or
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * if the given <var>implementation</var> does not implement the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * specified interface.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @since 1.6
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public <T> StandardMBean(T implementation, Class<T> mbeanInterface,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync boolean isMXBean) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync try {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync construct(implementation, mbeanInterface, false, isMXBean);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } catch (NotCompliantMBeanException e) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync throw new IllegalArgumentException(e);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Make a DynamicMBean out of <var>this</var>, using the specified
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>mbeanInterface</var> class, and choosing whether the resulting
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBean is an MXBean. This constructor can be used
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * to make either Standard MBeans or MXBeans. Unlike the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * constructor {@link #StandardMBean(Object, Class)}, it
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * does not throw NotCompliantMBeanException.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Calls {@link #StandardMBean(java.lang.Object, java.lang.Class, boolean)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * this(this, mbeanInterface, isMXBean)}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * This constructor is reserved to subclasses.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param mbeanInterface The Management Interface exported by this
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param isMXBean If true, the {@code mbeanInterface} parameter
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * names an MXBean interface and the resultant MBean is an MXBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @exception IllegalArgumentException if the <var>mbeanInterface</var>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * does not follow JMX design patterns for Management Interfaces, or
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * if <var>this</var> does not implement the specified interface.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @since 1.6
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected StandardMBean(Class<?> mbeanInterface, boolean isMXBean) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync try {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync construct(null, mbeanInterface, true, isMXBean);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } catch (NotCompliantMBeanException e) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync throw new IllegalArgumentException(e);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync }
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync /**
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync * <p>Replace the implementation object wrapped in this object.</p>
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync *
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync * @param implementation The new implementation of this Standard MBean
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync * (or MXBean). The <code>implementation</code> object must implement
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync * the Standard MBean (or MXBean) interface that was supplied when this
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync * <code>StandardMBean</code> was constructed.
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync *
f2cc35c5affd2fc618b3fd5379f67d5e424b5d04vboxsync * @exception IllegalArgumentException if the given
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>implementation</var> is null.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @exception NotCompliantMBeanException if the given
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>implementation</var> does not implement the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Standard MBean (or MXBean) interface that was
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * supplied at construction.
4e4a8e041182dff5c52892bee58a5d8f58f4bdadvboxsync *
4e4a8e041182dff5c52892bee58a5d8f58f4bdadvboxsync * @see #getImplementation
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public void setImplementation(Object implementation)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync throws NotCompliantMBeanException {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (implementation == null)
7fa1e4735b385f437dc86c75f13ef1b9a1e19e86vboxsync throw new IllegalArgumentException("implementation is null");
7fa1e4735b385f437dc86c75f13ef1b9a1e19e86vboxsync
7fa1e4735b385f437dc86c75f13ef1b9a1e19e86vboxsync if (isMXBean()) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync this.mbean = new MXBeanSupport(implementation,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync Util.<Class<Object>>cast(getMBeanInterface()));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync this.mbean = new StandardMBeanSupport(implementation,
73334d216e090057ca9631df4a4bbf8fa5ba529fvboxsync Util.<Class<Object>>cast(getMBeanInterface()));
73334d216e090057ca9631df4a4bbf8fa5ba529fvboxsync }
73334d216e090057ca9631df4a4bbf8fa5ba529fvboxsync }
73334d216e090057ca9631df4a4bbf8fa5ba529fvboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the implementation of this Standard MBean (or MXBean).
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return The implementation of this Standard MBean (or MXBean).
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @see #setImplementation
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public Object getImplementation() {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return mbean.getResource();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the Management Interface of this Standard MBean (or MXBean).
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return The management interface of this Standard MBean (or MXBean).
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public final Class<?> getMBeanInterface() {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return mbean.getMBeanInterface();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the class of the implementation of this Standard MBean (or MXBean).
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync * @return The class of the implementation of this Standard MBean (or MXBean).
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync **/
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync public Class<?> getImplementationClass() {
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync return mbean.getResource().getClass();
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync }
ef5a42216c548ecbd679d618f2e2122867bc00eavboxsync
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync // ------------------------------------------------------------------
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync // From the DynamicMBean interface.
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync // ------------------------------------------------------------------
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync public Object getAttribute(String attribute)
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync throws AttributeNotFoundException,
c6711025c2f5c5e7ecafed09f09551288afe53d9vboxsync MBeanException,
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync ReflectionException {
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync return mbean.getAttribute(attribute);
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync }
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync // ------------------------------------------------------------------
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync // From the DynamicMBean interface.
db1b3939027d4f297c8ca7a4e5da3168baefea2avboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public void setAttribute(Attribute attribute)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync throws AttributeNotFoundException,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync InvalidAttributeValueException,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanException,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ReflectionException {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync mbean.setAttribute(attribute);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
31771163041e3661403a806eb3382d2a165c003bvboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // From the DynamicMBean interface.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public AttributeList getAttributes(String[] attributes) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return mbean.getAttributes(attributes);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // From the DynamicMBean interface.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public AttributeList setAttributes(AttributeList attributes) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return mbean.setAttributes(attributes);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // From the DynamicMBean interface.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public Object invoke(String actionName, Object params[], String signature[])
31771163041e3661403a806eb3382d2a165c003bvboxsync throws MBeanException, ReflectionException {
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync return mbean.invoke(actionName, params, signature);
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync }
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync /**
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * Get the {@link MBeanInfo} for this MBean.
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * <p>
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * This method implements
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * {@link javax.management.DynamicMBean#getMBeanInfo()
cc4aab23dd31c9fb50c17bb4f3e90b401160c1b5vboxsync * DynamicMBean.getMBeanInfo()}.
e0d6f087507011df5f570f6800a2c332f8970e58vboxsync * <p>
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * This method first calls {@link #getCachedMBeanInfo()} in order to
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * retrieve the cached MBeanInfo for this MBean, if any. If the
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * MBeanInfo returned by {@link #getCachedMBeanInfo()} is not null,
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * then it is returned.<br>
9d091bd19338b94d7dae910bf5767923ef6d4562vboxsync * Otherwise, this method builds a default MBeanInfo for this MBean,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * using the Management Interface specified for this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * While building the MBeanInfo, this method calls the customization
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * hooks that make it possible for subclasses to supply their custom
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * descriptions, parameter names, etc...<br>
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * Finally, it calls {@link #cacheMBeanInfo(javax.management.MBeanInfo)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * cacheMBeanInfo()} in order to cache the new MBeanInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return The cached MBeanInfo for that MBean, if not null, or a
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync * newly built MBeanInfo if none was cached.
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync **/
2a2b173b54c259e34320ce0acf26f18e9382ce2avboxsync public MBeanInfo getMBeanInfo() {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync try {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanInfo cached = getCachedMBeanInfo();
d90eec53c9dcaa0f3d1054e8734ed46875b9093avboxsync if (cached != null) return cached;
d90eec53c9dcaa0f3d1054e8734ed46875b9093avboxsync } catch (RuntimeException x) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (MISC_LOGGER.isLoggable(Level.FINEST)) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MISC_LOGGER.logp(Level.FINEST,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanServerFactory.class.getName(), "getMBeanInfo",
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync "Failed to get cached MBeanInfo", x);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync if (MISC_LOGGER.isLoggable(Level.FINER)) {
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync MISC_LOGGER.logp(Level.FINER,
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync MBeanServerFactory.class.getName(), "getMBeanInfo",
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync "Building MBeanInfo for " +
31771163041e3661403a806eb3382d2a165c003bvboxsync getImplementationClass().getName());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanSupport<?> msupport = mbean;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanInfo bi = msupport.getMBeanInfo();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final Object impl = msupport.getResource();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final boolean immutableInfo = immutableInfo(this.getClass());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final String cname = getClassName(bi);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final String text = getDescription(bi);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanConstructorInfo[] ctors = getConstructors(bi,impl);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanAttributeInfo[] attrs = getAttributes(bi);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanOperationInfo[] ops = getOperations(bi);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanNotificationInfo[] ntfs = getNotifications(bi);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final Descriptor desc = getDescriptor(bi, immutableInfo);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanInfo nmbi = new MBeanInfo(
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync cname, text, attrs, ctors, ops, ntfs, desc);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync try {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync cacheMBeanInfo(nmbi);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } catch (RuntimeException x) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (MISC_LOGGER.isLoggable(Level.FINEST)) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MISC_LOGGER.logp(Level.FINEST,
f455158a85f95b4886cbe7154b067144b815c125vboxsync MBeanServerFactory.class.getName(), "getMBeanInfo",
96ae72f2a0b572599ee8b3f95907beeb66bfbf72vboxsync "Failed to cache MBeanInfo", x);
cb13d6af84f80841e712dd344158f2e2bdb1a8b2vboxsync }
cb13d6af84f80841e712dd344158f2e2bdb1a8b2vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return nmbi;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
cb13d6af84f80841e712dd344158f2e2bdb1a8b2vboxsync * Get the className that will be used in the MBeanInfo returned by
cb13d6af84f80841e712dd344158f2e2bdb1a8b2vboxsync * this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom class name. The default implementation returns
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@link MBeanInfo#getClassName() info.getClassName()}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info The default MBeanInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the class name for the new MBeanInfo.
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync **/
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync protected String getClassName(MBeanInfo info) {
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync if (info == null) return getImplementationClass().getName();
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync return info.getClassName();
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync }
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync /**
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync * Customization hook:
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync * Get the description that will be used in the MBeanInfo returned by
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync * this MBean.
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync * <br>
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync * Subclasses may redefine this method in order to supply their
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync * custom MBean description. The default implementation returns
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync * {@link MBeanInfo#getDescription() info.getDescription()}.
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync * @param info The default MBeanInfo derived by reflection.
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync * @return the description for the new MBeanInfo.
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync **/
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync protected String getDescription(MBeanInfo info) {
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync if (info == null) return null;
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync return info.getDescription();
e52b0dfe3d9ead70e24f2ce4ed3faa6c79c00618vboxsync }
1f96defca77af991e72fed46159433af9ae6b73evboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7757e065b2ef522ec99a434fbeeae8665a36543avboxsync * <p>Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the description that will be used in the MBeanFeatureInfo
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * returned by this MBean.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Subclasses may redefine this method in order to supply
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync * their custom description. The default implementation returns
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync * {@link MBeanFeatureInfo#getDescription()
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * info.getDescription()}.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>This method is called by
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync * {@link #getDescription(MBeanAttributeInfo)},
7757e065b2ef522ec99a434fbeeae8665a36543avboxsync * {@link #getDescription(MBeanOperationInfo)},
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync * {@link #getDescription(MBeanConstructorInfo)}.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info The default MBeanFeatureInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the description for the given MBeanFeatureInfo.
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync **/
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync protected String getDescription(MBeanFeatureInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (info == null) return null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return info.getDescription();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the description that will be used in the MBeanAttributeInfo
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync * returned by this MBean.
dbc6ecd6a6e372b8dcdf31d68bdab2d5b5e604d2vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom description. The default implementation returns {@link
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * #getDescription(MBeanFeatureInfo)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * getDescription((MBeanFeatureInfo) info)}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info The default MBeanAttributeInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the description for the given MBeanAttributeInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected String getDescription(MBeanAttributeInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return getDescription((MBeanFeatureInfo)info);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
036edb9371a19903dd703cdb959348a2726d7a38vboxsync /**
036edb9371a19903dd703cdb959348a2726d7a38vboxsync * Customization hook:
ab455939477d81b7bb500586f88029d3a3c0b34cvboxsync * Get the description that will be used in the MBeanConstructorInfo
036edb9371a19903dd703cdb959348a2726d7a38vboxsync * returned by this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom description.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * The default implementation returns {@link
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * #getDescription(MBeanFeatureInfo)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * getDescription((MBeanFeatureInfo) info)}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info The default MBeanConstructorInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the description for the given MBeanConstructorInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected String getDescription(MBeanConstructorInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return getDescription((MBeanFeatureInfo)info);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the description that will be used for the <var>sequence</var>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
2a2b173b54c259e34320ce0acf26f18e9382ce2avboxsync * Subclasses may redefine this method in order to supply their
2a2b173b54c259e34320ce0acf26f18e9382ce2avboxsync * custom description. The default implementation returns
2a2b173b54c259e34320ce0acf26f18e9382ce2avboxsync * {@link MBeanParameterInfo#getDescription() param.getDescription()}.
2a2b173b54c259e34320ce0acf26f18e9382ce2avboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param ctor The default MBeanConstructorInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param param The default MBeanParameterInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param sequence The sequence number of the parameter considered
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * ("0" for the first parameter, "1" for the second parameter,
f455158a85f95b4886cbe7154b067144b815c125vboxsync * etc...).
f455158a85f95b4886cbe7154b067144b815c125vboxsync * @return the description for the given MBeanParameterInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected String getDescription(MBeanConstructorInfo ctor,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanParameterInfo param,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync int sequence) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (param == null) return null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return param.getDescription();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
97a22e235416469499b353dfec11fc90c79df178vboxsync * Get the name that will be used for the <var>sequence</var>
97a22e235416469499b353dfec11fc90c79df178vboxsync * MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom parameter name. The default implementation returns
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@link MBeanParameterInfo#getName() param.getName()}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param ctor The default MBeanConstructorInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param param The default MBeanParameterInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param sequence The sequence number of the parameter considered
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * ("0" for the first parameter, "1" for the second parameter,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * etc...).
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the name for the given MBeanParameterInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected String getParameterName(MBeanConstructorInfo ctor,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanParameterInfo param,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync int sequence) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (param == null) return null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return param.getName();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
64488ef82ba83214fc6454dd6f2d91b7e953cdf6vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the description that will be used in the MBeanOperationInfo
a2e54e22e7687863f9b4020659bcb6436d5a9963vboxsync * returned by this MBean.
a2e54e22e7687863f9b4020659bcb6436d5a9963vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom description. The default implementation returns
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@link #getDescription(MBeanFeatureInfo)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * getDescription((MBeanFeatureInfo) info)}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info The default MBeanOperationInfo derived by reflection.
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync * @return the description for the given MBeanOperationInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected String getDescription(MBeanOperationInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return getDescription((MBeanFeatureInfo)info);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the <var>impact</var> flag of the operation that will be used in
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * the MBeanOperationInfo returned by this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom impact flag. The default implementation returns
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@link MBeanOperationInfo#getImpact() info.getImpact()}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info The default MBeanOperationInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the impact flag for the given MBeanOperationInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected int getImpact(MBeanOperationInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (info == null) return MBeanOperationInfo.UNKNOWN;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return info.getImpact();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the name that will be used for the <var>sequence</var>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom parameter name. The default implementation returns
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@link MBeanParameterInfo#getName() param.getName()}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param op The default MBeanOperationInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param param The default MBeanParameterInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param sequence The sequence number of the parameter considered
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * ("0" for the first parameter, "1" for the second parameter,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * etc...).
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the name to use for the given MBeanParameterInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected String getParameterName(MBeanOperationInfo op,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanParameterInfo param,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync int sequence) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (param == null) return null;
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync return param.getName();
fa6dbd9c9e9645298cca864aa561382469907905vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the description that will be used for the <var>sequence</var>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom description. The default implementation returns
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@link MBeanParameterInfo#getDescription() param.getDescription()}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param op The default MBeanOperationInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param param The default MBeanParameterInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param sequence The sequence number of the parameter considered
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * ("0" for the first parameter, "1" for the second parameter,
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * etc...).
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the description for the given MBeanParameterInfo.
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected String getDescription(MBeanOperationInfo op,
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync MBeanParameterInfo param,
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync int sequence) {
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync if (param == null) return null;
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync return param.getDescription();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Customization hook:
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync * Get the MBeanConstructorInfo[] that will be used in the MBeanInfo
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * returned by this MBean.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * <br>
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * By default, this method returns <code>null</code> if the wrapped
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * implementation is not <var>this</var>. Indeed, if the wrapped
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * implementation is not this object itself, it will not be possible
69e691ae98ad8d1b3c697e22704da6f73fa1dbedvboxsync * to recreate a wrapped implementation by calling the implementation
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * constructors through <code>MBeanServer.createMBean(...)</code>.<br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Otherwise, if the wrapped implementation is <var>this</var>,
d462687a4bb8aa43108a06b1cdfde02c49037b1bvboxsync * <var>ctors</var> is returned.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to modify this
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * behavior, if needed.
0c8e85263a357c44964520942cb5816ab1c2e69dvboxsync * @param ctors The default MBeanConstructorInfo[] derived by reflection.
d1bb48754376874c3cc6b1091a6abec549663c0cvboxsync * @param impl The wrapped implementation. If <code>null</code> is
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * passed, the wrapped implementation is ignored and
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <var>ctors</var> is returned.
800f04f116f4749015385fac39c12ba0166813c1vboxsync * @return the MBeanConstructorInfo[] for the new MBeanInfo.
800f04f116f4749015385fac39c12ba0166813c1vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected MBeanConstructorInfo[]
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync getConstructors(MBeanConstructorInfo[] ctors, Object impl) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (ctors == null) return null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (impl != null && impl != this) return null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return ctors;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Get the MBeanNotificationInfo[] that will be used in the MBeanInfo
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * returned by this MBean.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <br>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Subclasses may redefine this method in order to supply their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * custom notifications.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info The default MBeanInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the MBeanNotificationInfo[] for the new MBeanInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanNotificationInfo[] getNotifications(MBeanInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Get the Descriptor that will be used in the MBeanInfo
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * returned by this MBean.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Subclasses may redefine this method in order to supply
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * their custom descriptor.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>The default implementation of this method returns a Descriptor
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * that contains at least the field {@code interfaceClassName}, with
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * value {@link #getMBeanInterface()}.getName(). It may also contain
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * the field {@code immutableInfo}, with a value that is the string
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@code "true"} if the implementation can determine that the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@code MBeanInfo} returned by {@link #getMBeanInfo()} will always
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * be the same. It may contain other fields: fields defined by the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * JMX specification must have appropriate values, and other fields
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * must follow the conventions for non-standard field names.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info The default MBeanInfo derived by reflection.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return the Descriptor for the new MBeanInfo.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync */
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync Descriptor getDescriptor(MBeanInfo info, boolean immutableInfo) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ImmutableDescriptor desc;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (info == null ||
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync info.getDescriptor() == null ||
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync info.getDescriptor().getFieldNames().length == 0) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final String interfaceClassNameS =
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync "interfaceClassName=" + getMBeanInterface().getName();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final String immutableInfoS =
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync "immutableInfo=" + immutableInfo;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync desc = new ImmutableDescriptor(interfaceClassNameS, immutableInfoS);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync desc = descriptors.get(desc);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync Descriptor d = info.getDescriptor();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync Map<String,Object> fields = new HashMap<String,Object>();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync for (String fieldName : d.getFieldNames()) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (fieldName.equals("immutableInfo")) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // Replace immutableInfo as the underlying MBean/MXBean
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // could already implement NotificationBroadcaster and
6a11a038ef83aba6a5e744e92acb8ce1a48db2b7vboxsync // return immutableInfo=true in its MBeanInfo.
6a11a038ef83aba6a5e744e92acb8ce1a48db2b7vboxsync fields.put(fieldName, Boolean.toString(immutableInfo));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
6a11a038ef83aba6a5e744e92acb8ce1a48db2b7vboxsync fields.put(fieldName, d.getFieldValue(fieldName));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync desc = new ImmutableDescriptor(fields);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return desc;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Return the MBeanInfo cached for this object.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Subclasses may redefine this method in order to implement their
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * own caching policy. The default implementation stores one
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@link MBeanInfo} object per instance.
78617101552bfc0ac15031a25353d67fe049fd8evboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return The cached MBeanInfo, or null if no MBeanInfo is cached.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @see #cacheMBeanInfo(MBeanInfo)
78617101552bfc0ac15031a25353d67fe049fd8evboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected MBeanInfo getCachedMBeanInfo() {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return cachedMBeanInfo;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Customization hook:
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * cache the MBeanInfo built for this object.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Subclasses may redefine this method in order to implement
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * their own caching policy. The default implementation stores
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <code>info</code> in this instance. A subclass can define
65169cfba1adfc4c86c2b6b99a0b8e67ed216a23vboxsync * other policies, such as not saving <code>info</code> (so it is
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * reconstructed every time {@link #getMBeanInfo()} is called) or
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * sharing a unique {@link MBeanInfo} object when several
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <code>StandardMBean</code> instances have equal {@link
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBeanInfo} values.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @param info the new <code>MBeanInfo</code> to cache. Any
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * previously cached value is discarded. This parameter may be
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * null, in which case there is no new cached value.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync **/
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync protected void cacheMBeanInfo(MBeanInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync cachedMBeanInfo = info;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync private boolean isMXBean() {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return mbean.isMXBean();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private static <T> boolean identicalArrays(T[] a, T[] b) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (a == b)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return true;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (a == null || b == null || a.length != b.length)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return false;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync for (int i = 0; i < a.length; i++) {
78617101552bfc0ac15031a25353d67fe049fd8evboxsync if (a[i] != b[i])
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return false;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
78617101552bfc0ac15031a25353d67fe049fd8evboxsync return true;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private static <T> boolean equal(T a, T b) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (a == b)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return true;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (a == null || b == null)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return false;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return a.equals(b);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private static MBeanParameterInfo
69e691ae98ad8d1b3c697e22704da6f73fa1dbedvboxsync customize(MBeanParameterInfo pi,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync String name,
49bcf64aaacb2de9703cdd3633eec0a2610c3cf3vboxsync String description) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (equal(name, pi.getName()) &&
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync equal(description, pi.getDescription()))
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return pi;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync else if (pi instanceof OpenMBeanParameterInfo) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync OpenMBeanParameterInfo opi = (OpenMBeanParameterInfo) pi;
49bcf64aaacb2de9703cdd3633eec0a2610c3cf3vboxsync return new OpenMBeanParameterInfoSupport(name,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync opi.getOpenType(),
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync pi.getDescriptor());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return new MBeanParameterInfo(name,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync pi.getType(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync pi.getDescriptor());
e9589ad7866837c7c90b7337aa53bf604e8e36e2vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private static MBeanConstructorInfo
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync customize(MBeanConstructorInfo ci,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync String description,
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync MBeanParameterInfo[] signature) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (equal(description, ci.getDescription()) &&
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync identicalArrays(signature, ci.getSignature()))
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return ci;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (ci instanceof OpenMBeanConstructorInfo) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync OpenMBeanParameterInfo[] oparams =
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync paramsToOpenParams(signature);
dd3b708fb52e912a0a07fab811a5427d5abf15e6vboxsync return new OpenMBeanConstructorInfoSupport(ci.getName(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync oparams,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ci.getDescriptor());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return new MBeanConstructorInfo(ci.getName(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync signature,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ci.getDescriptor());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
69e691ae98ad8d1b3c697e22704da6f73fa1dbedvboxsync private static MBeanOperationInfo
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync customize(MBeanOperationInfo oi,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync String description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanParameterInfo[] signature,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync int impact) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (equal(description, oi.getDescription()) &&
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync identicalArrays(signature, oi.getSignature()) &&
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync impact == oi.getImpact())
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return oi;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (oi instanceof OpenMBeanOperationInfo) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync OpenMBeanParameterInfo[] oparams =
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync paramsToOpenParams(signature);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return new OpenMBeanOperationInfoSupport(oi.getName(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync oparams,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ooi.getReturnOpenType(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync impact,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync oi.getDescriptor());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return new MBeanOperationInfo(oi.getName(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync signature,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync oi.getReturnType(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync impact,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync oi.getDescriptor());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
dd3b708fb52e912a0a07fab811a5427d5abf15e6vboxsync
cb62273b023a1efb7864e02410a10fce430bc050vboxsync private static MBeanAttributeInfo
21372013711722fd2b5f3a1f3cb4d512e2486afdvboxsync customize(MBeanAttributeInfo ai,
cb62273b023a1efb7864e02410a10fce430bc050vboxsync String description) {
cb62273b023a1efb7864e02410a10fce430bc050vboxsync if (equal(description, ai.getDescription()))
cb62273b023a1efb7864e02410a10fce430bc050vboxsync return ai;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (ai instanceof OpenMBeanAttributeInfo) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync OpenMBeanAttributeInfo oai = (OpenMBeanAttributeInfo) ai;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return new OpenMBeanAttributeInfoSupport(ai.getName(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync oai.getOpenType(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.isReadable(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.isWritable(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.isIs(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.getDescriptor());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return new MBeanAttributeInfo(ai.getName(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.getType(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync description,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.isReadable(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.isWritable(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.isIs(),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync ai.getDescriptor());
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync private static OpenMBeanParameterInfo[]
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync paramsToOpenParams(MBeanParameterInfo[] params) {
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync if (params instanceof OpenMBeanParameterInfo[])
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync return (OpenMBeanParameterInfo[]) params;
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync OpenMBeanParameterInfo[] oparams =
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync new OpenMBeanParameterInfoSupport[params.length];
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync System.arraycopy(params, 0, oparams, 0, params.length);
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync return oparams;
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync }
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync // ------------------------------------------------------------------
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync // Build the custom MBeanConstructorInfo[]
4f4877d6f6ea6dbe54cba4595450e5c837d5d419vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private MBeanConstructorInfo[]
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync getConstructors(MBeanInfo info, Object impl) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanConstructorInfo[] ctors =
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync getConstructors(info.getConstructors(), impl);
d55f5ac020ffc727e495eebc00ff75a022bbd27avboxsync if (ctors == null)
d55f5ac020ffc727e495eebc00ff75a022bbd27avboxsync return null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final int ctorlen = ctors.length;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanConstructorInfo[] nctors = new MBeanConstructorInfo[ctorlen];
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync for (int i=0; i<ctorlen; i++) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanConstructorInfo c = ctors[i];
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanParameterInfo[] params = c.getSignature();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanParameterInfo[] nps;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (params != null) {
04bce18d27791abed8346aba0de41c53a2acd81avboxsync final int plen = params.length;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync nps = new MBeanParameterInfo[plen];
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync for (int ii=0;ii<plen;ii++) {
04bce18d27791abed8346aba0de41c53a2acd81avboxsync MBeanParameterInfo p = params[ii];
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync nps[ii] = customize(p,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync getParameterName(c,p,ii),
cc5de66a9d41c329004f8bd916b6cb4fe0014c68vboxsync getDescription(c,p,ii));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync nps = null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync nctors[i] =
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync customize(c, getDescription(c), nps);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
c0b6af690ad705bddfa87c643b89770a7a0aaf5avboxsync return nctors;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
917bfda215593dc13467684ab6bfa6b7f67cc5d2vboxsync
917bfda215593dc13467684ab6bfa6b7f67cc5d2vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // Build the custom MBeanOperationInfo[]
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private MBeanOperationInfo[] getOperations(MBeanInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanOperationInfo[] ops = info.getOperations();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (ops == null)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final int oplen = ops.length;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanOperationInfo[] nops = new MBeanOperationInfo[oplen];
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync for (int i=0; i<oplen; i++) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanOperationInfo o = ops[i];
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanParameterInfo[] params = o.getSignature();
bb933ee4eb48572fc6f1541d945c81141e233561vboxsync final MBeanParameterInfo[] nps;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (params != null) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final int plen = params.length;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync nps = new MBeanParameterInfo[plen];
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync for (int ii=0;ii<plen;ii++) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanParameterInfo p = params[ii];
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync nps[ii] = customize(p,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync getParameterName(o,p,ii),
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync getDescription(o,p,ii));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } else {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync nps = null;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync nops[i] = customize(o, getDescription(o), nps, getImpact(o));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return nops;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // Build the custom MBeanAttributeInfo[]
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // ------------------------------------------------------------------
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private MBeanAttributeInfo[] getAttributes(MBeanInfo info) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync final MBeanAttributeInfo[] atts = info.getAttributes();
10019aae08864f54606add8cef1a241932a0c8fcvboxsync if (atts == null)
2911253f827c3ce1e5438e8b518c4c7f5368fbcavboxsync return null; // should not happen
7f9a335e8fb0442971f42e4ac695f6f8832095b7vboxsync final MBeanAttributeInfo[] natts;
287c6f53c46cca9235fcdc60e79229f336c23461vboxsync final int attlen = atts.length;
2911253f827c3ce1e5438e8b518c4c7f5368fbcavboxsync natts = new MBeanAttributeInfo[attlen];
7d67a9be8c4cdeac7a114229784de49dc1d21307vboxsync for (int i=0; i<attlen; i++) {
7d67a9be8c4cdeac7a114229784de49dc1d21307vboxsync final MBeanAttributeInfo a = atts[i];
e420253a89a6e07613f49cfd9a1db9e217039575vboxsync natts[i] = customize(a, getDescription(a));
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return natts;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Allows the MBean to perform any operations it needs before
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * being registered in the MBean server. If the name of the MBean
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * is not specified, the MBean can provide a name for its
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * registration. If any exception is raised, the MBean will not be
69e691ae98ad8d1b3c697e22704da6f73fa1dbedvboxsync * registered in the MBean server.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
9c2f0f35331ebfb1809126f5d6e30b2b4a889360vboxsync * <p>The default implementation of this method returns the {@code name}
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * parameter. It does nothing else for
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Standard MBeans. For MXBeans, it records the {@code MBeanServer}
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * and {@code ObjectName} parameters so they can be used to translate
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * inter-MXBean references.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>It is good practice for a subclass that overrides this method
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * to call the overridden method via {@code super.preRegister(...)}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * This is necessary if this object is an MXBean that is referenced
d1bb48754376874c3cc6b1091a6abec549663c0cvboxsync * by attributes or operations in other MXBeans.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
3f2f91afeed4e8cb37bea26c44380ea8252103a0vboxsync * @param server The MBean server in which the MBean will be registered.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * @param name The object name of the MBean. This name is null if
1eda04de692c4c416332941e87bab4cc8fc45a18vboxsync * the name parameter to one of the <code>createMBean</code> or
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <code>registerMBean</code> methods in the {@link MBeanServer}
d1bb48754376874c3cc6b1091a6abec549663c0cvboxsync * interface is null. In that case, this method must return a
4e055140bcd2406a7ebade59f30db5ca8d13219cvboxsync * non-null ObjectName for the new MBean.
5d132e4f59824af86c65bf410d2318fb971ab314vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @return The name under which the MBean is to be registered.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * This value must not be null. If the <code>name</code>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * parameter is not null, it will usually but not necessarily be
00fc6ac8df60b81c37900a4e987a0d02bac39903vboxsync * the returned value.
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync *
a2af3325cd2539bfcca532f15b1c7683272888cevboxsync * @throws IllegalArgumentException if this is an MXBean and
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * {@code name} is null.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @throws InstanceAlreadyExistsException if this is an MXBean and
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * it has already been registered under another name (in this
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * MBean Server or another).
8502773207230763deba3e622495f2099398dcb0vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @throws Exception no other checked exceptions are thrown by
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * this method but {@code Exception} is declared so that subclasses
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * can override the method and throw their own exceptions.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @since 1.6
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync */
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public ObjectName preRegister(MBeanServer server, ObjectName name)
cda4a68d59969f27d3063ff91c9c3f887d34c8f9vboxsync throws Exception {
cda4a68d59969f27d3063ff91c9c3f887d34c8f9vboxsync mbean.register(server, name);
cda4a68d59969f27d3063ff91c9c3f887d34c8f9vboxsync return name;
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
d1bb48754376874c3cc6b1091a6abec549663c0cvboxsync * <p>Allows the MBean to perform any operations needed after having been
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * registered in the MBean server or after the registration has failed.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>The default implementation of this method does nothing for
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Standard MBeans. For MXBeans, it undoes any work done by
939e2ecb812c6402abcc63e7d615c5444acfd02evboxsync * {@link #preRegister preRegister} if registration fails.</p>
115ba3435de2659844b3cdb449f8c178a246dee8vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>It is good practice for a subclass that overrides this method
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * to call the overridden method via {@code super.postRegister(...)}.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * This is necessary if this object is an MXBean that is referenced
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * by attributes or operations in other MXBeans.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
1729795f504cc1975ec195bca8b493c2faa0f5ddvboxsync * @param registrationDone Indicates whether or not the MBean has
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * been successfully registered in the MBean server. The value
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * false means that the registration phase has failed.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @since 1.6
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync */
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public void postRegister(Boolean registrationDone) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (!registrationDone)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync mbean.unregister();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>Allows the MBean to perform any operations it needs before
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * being unregistered by the MBean server.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>The default implementation of this method does nothing.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>It is good practice for a subclass that overrides this method
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * to call the overridden method via {@code super.preDeregister(...)}.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @throws Exception no checked exceptions are throw by this method
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * but {@code Exception} is declared so that subclasses can override
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * this method and throw their own exceptions.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * @since 1.6
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync */
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public void preDeregister() throws Exception {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /**
ed65cb72708fa824c83162ab8604d35e90f78ce9vboxsync * <p>Allows the MBean to perform any operations needed after having been
b8601aa57872ad208a7ef5facab06c61d7886d60vboxsync * unregistered in the MBean server.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>The default implementation of this method does nothing for
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Standard MBeans. For MXBeans, it removes any information that
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * was recorded by the {@link #preRegister preRegister} method.</p>
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync *
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * <p>It is good practice for a subclass that overrides this method
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * to call the overridden method via {@code super.postRegister(...)}.
4dcf37df51439573b55cc16f53590c7b68cb1051vboxsync * This is necessary if this object is an MXBean that is referenced
4dcf37df51439573b55cc16f53590c7b68cb1051vboxsync * by attributes or operations in other MXBeans.</p>
4dcf37df51439573b55cc16f53590c7b68cb1051vboxsync *
4dcf37df51439573b55cc16f53590c7b68cb1051vboxsync * @since 1.6
4dcf37df51439573b55cc16f53590c7b68cb1051vboxsync */
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public void postDeregister() {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync mbean.unregister();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync //
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // MBeanInfo immutability
0b53618bc8b692bf8ed1499ba786f5959295c633vboxsync //
0b53618bc8b692bf8ed1499ba786f5959295c633vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Cached results of previous calls to immutableInfo. This is
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * a WeakHashMap so that we don't prevent a class from being
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * garbage collected just because we know whether its MBeanInfo
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * is immutable.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync */
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private static final Map<Class<?>, Boolean> mbeanInfoSafeMap =
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync new WeakHashMap<Class<?>, Boolean>();
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /**
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * Return true if {@code subclass} is known to preserve the immutability
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * of the {@code MBeanInfo}. The {@code subclass} is considered to have
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * an immutable {@code MBeanInfo} if it does not override any of the
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * getMBeanInfo, getCachedMBeanInfo, cacheMBeanInfo and getNotificationInfo
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync * methods.
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync */
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync static boolean immutableInfo(Class<? extends StandardMBean> subclass) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (subclass == StandardMBean.class ||
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync subclass == StandardEmitterMBean.class)
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return true;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync synchronized (mbeanInfoSafeMap) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync Boolean safe = mbeanInfoSafeMap.get(subclass);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (safe == null) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync try {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanInfoSafeAction action =
230bd8589bba39933ac5ec21482d6186d675e604vboxsync new MBeanInfoSafeAction(subclass);
230bd8589bba39933ac5ec21482d6186d675e604vboxsync safe = AccessController.doPrivileged(action);
230bd8589bba39933ac5ec21482d6186d675e604vboxsync } catch (Exception e) { // e.g. SecurityException
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync /* We don't know, so we assume it isn't. */
ce617464bdeee0bbae0058f64069d14092cc6522vboxsync safe = false;
4a0366aedca1d15db264a395a4b4b409e05516e6vboxsync }
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync mbeanInfoSafeMap.put(subclass, safe);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync }
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync return safe;
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync }
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync static boolean overrides(Class<?> subclass, Class<?> superclass,
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync String name, Class<?>... params) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync for (Class<?> c = subclass; c != superclass; c = c.getSuperclass()) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync try {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync c.getDeclaredMethod(name, params);
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return true;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync } catch (NoSuchMethodException e) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // OK: this class doesn't override it
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return false;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private static class MBeanInfoSafeAction
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync implements PrivilegedAction<Boolean> {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync private final Class<?> subclass;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync MBeanInfoSafeAction(Class<?> subclass) {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync this.subclass = subclass;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync public Boolean run() {
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync // Check for "void cacheMBeanInfo(MBeanInfo)" method.
9de47c4ec7b0fc9a384e4b815153de399da7b8devboxsync //
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync if (overrides(subclass, StandardMBean.class,
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync "cacheMBeanInfo", MBeanInfo.class))
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync return false;
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync // Check for "MBeanInfo getCachedMBeanInfo()" method.
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync //
9de47c4ec7b0fc9a384e4b815153de399da7b8devboxsync if (overrides(subclass, StandardMBean.class,
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync "getCachedMBeanInfo", (Class<?>[]) null))
9de47c4ec7b0fc9a384e4b815153de399da7b8devboxsync return false;
9de47c4ec7b0fc9a384e4b815153de399da7b8devboxsync
9de47c4ec7b0fc9a384e4b815153de399da7b8devboxsync // Check for "MBeanInfo getMBeanInfo()" method.
9de47c4ec7b0fc9a384e4b815153de399da7b8devboxsync //
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync if (overrides(subclass, StandardMBean.class,
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync "getMBeanInfo", (Class<?>[]) null))
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync return false;
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync // Check for "MBeanNotificationInfo[] getNotificationInfo()"
36411046d85fccaa66061120a064225fd1b5ae01vboxsync // method.
36411046d85fccaa66061120a064225fd1b5ae01vboxsync //
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync // This method is taken into account for the MBeanInfo
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync // immutability checks if and only if the given subclass is
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync // StandardEmitterMBean itself or can be assigned to
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync // StandardEmitterMBean.
f5edc444546b57af847ae33f2bd1e10442496e47vboxsync //
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync if (StandardEmitterMBean.class.isAssignableFrom(subclass))
0229b85e94ec942dbb9b8748e9dbb30cef9f3ed9vboxsync if (overrides(subclass, StandardEmitterMBean.class,
672b9b73c5db0590fa77ef0f26b024d4e61bad86vboxsync "getNotificationInfo", (Class<?>[]) null))
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return false;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync return true;
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync }
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync}
7383be37f7fdafd682028c4ab39ffeab51fccc36vboxsync