com.sun.jmx.mbeanserver.Introspector Java Examples

The following examples show how to use com.sun.jmx.mbeanserver.Introspector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultMBeanServerInterceptor.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #2
Source File: DefaultMBeanServerInterceptor.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #3
Source File: JMX.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Test whether an interface is an MXBean interface.
 * An interface is an MXBean interface if it is public,
 * annotated {@link MXBean &#64;MXBean} or {@code @MXBean(true)}
 * or if it does not have an {@code @MXBean} annotation
 * and its name ends with "{@code MXBean}".</p>
 *
 * @param interfaceClass The candidate interface.
 *
 * @return true if {@code interfaceClass} is a
 * {@link javax.management.MXBean compliant MXBean interface}
 *
 * @throws NullPointerException if {@code interfaceClass} is null.
 */
public static boolean isMXBeanInterface(Class<?> interfaceClass) {
    if (!interfaceClass.isInterface())
        return false;
    if (!Modifier.isPublic(interfaceClass.getModifiers()) &&
        !Introspector.ALLOW_NONPUBLIC_MBEAN) {
        return false;
    }
    MXBean a = interfaceClass.getAnnotation(MXBean.class);
    if (a != null)
        return a.value();
    return interfaceClass.getName().endsWith("MXBean");
    // We don't bother excluding the case where the name is
    // exactly the string "MXBean" since that would mean there
    // was no package name, which is pretty unlikely in practice.
}
 
Example #4
Source File: DefaultMBeanServerInterceptor.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #5
Source File: DefaultMBeanServerInterceptor.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #6
Source File: DefaultMBeanServerInterceptor.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #7
Source File: DefaultMBeanServerInterceptor.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #8
Source File: JMX.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Test whether an interface is an MXBean interface.
 * An interface is an MXBean interface if it is public,
 * annotated {@link MXBean &#64;MXBean} or {@code @MXBean(true)}
 * or if it does not have an {@code @MXBean} annotation
 * and its name ends with "{@code MXBean}".</p>
 *
 * @param interfaceClass The candidate interface.
 *
 * @return true if {@code interfaceClass} is a
 * {@link javax.management.MXBean compliant MXBean interface}
 *
 * @throws NullPointerException if {@code interfaceClass} is null.
 */
public static boolean isMXBeanInterface(Class<?> interfaceClass) {
    if (!interfaceClass.isInterface())
        return false;
    if (!Modifier.isPublic(interfaceClass.getModifiers()) &&
        !Introspector.ALLOW_NONPUBLIC_MBEAN) {
        return false;
    }
    MXBean a = interfaceClass.getAnnotation(MXBean.class);
    if (a != null)
        return a.value();
    return interfaceClass.getName().endsWith("MXBean");
    // We don't bother excluding the case where the name is
    // exactly the string "MXBean" since that would mean there
    // was no package name, which is pretty unlikely in practice.
}
 
Example #9
Source File: DefaultMBeanServerInterceptor.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #10
Source File: DefaultMBeanServerInterceptor.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #11
Source File: JMX.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Test whether an interface is an MXBean interface.
 * An interface is an MXBean interface if it is public,
 * annotated {@link MXBean &#64;MXBean} or {@code @MXBean(true)}
 * or if it does not have an {@code @MXBean} annotation
 * and its name ends with "{@code MXBean}".</p>
 *
 * @param interfaceClass The candidate interface.
 *
 * @return true if {@code interfaceClass} is a
 * {@link javax.management.MXBean compliant MXBean interface}
 *
 * @throws NullPointerException if {@code interfaceClass} is null.
 */
public static boolean isMXBeanInterface(Class<?> interfaceClass) {
    if (!interfaceClass.isInterface())
        return false;
    if (!Modifier.isPublic(interfaceClass.getModifiers()) &&
        !Introspector.ALLOW_NONPUBLIC_MBEAN) {
        return false;
    }
    MXBean a = interfaceClass.getAnnotation(MXBean.class);
    if (a != null)
        return a.value();
    return interfaceClass.getName().endsWith("MXBean");
    // We don't bother excluding the case where the name is
    // exactly the string "MXBean" since that would mean there
    // was no package name, which is pretty unlikely in practice.
}
 
Example #12
Source File: DefaultMBeanServerInterceptor.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #13
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #14
Source File: JMX.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Test whether an interface is an MXBean interface.
 * An interface is an MXBean interface if it is public,
 * annotated {@link MXBean &#64;MXBean} or {@code @MXBean(true)}
 * or if it does not have an {@code @MXBean} annotation
 * and its name ends with "{@code MXBean}".</p>
 *
 * @param interfaceClass The candidate interface.
 *
 * @return true if {@code interfaceClass} is a
 * {@link javax.management.MXBean compliant MXBean interface}
 *
 * @throws NullPointerException if {@code interfaceClass} is null.
 */
public static boolean isMXBeanInterface(Class<?> interfaceClass) {
    if (!interfaceClass.isInterface())
        return false;
    if (!Modifier.isPublic(interfaceClass.getModifiers()) &&
        !Introspector.ALLOW_NONPUBLIC_MBEAN) {
        return false;
    }
    MXBean a = interfaceClass.getAnnotation(MXBean.class);
    if (a != null)
        return a.value();
    return interfaceClass.getName().endsWith("MXBean");
    // We don't bother excluding the case where the name is
    // exactly the string "MXBean" since that would mean there
    // was no package name, which is pretty unlikely in practice.
}
 
Example #15
Source File: DefaultMBeanServerInterceptor.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance registerMBean(Object object, ObjectName name)
    throws InstanceAlreadyExistsException, MBeanRegistrationException,
    NotCompliantMBeanException  {

    // ------------------------------
    // ------------------------------
    Class<?> theClass = object.getClass();

    Introspector.checkCompliance(theClass);

    final String infoClassName = getNewMBeanClassName(object);

    checkMBeanPermission(infoClassName, null, name, "registerMBean");
    checkMBeanTrustPermission(theClass);

    return registerObject(infoClassName, object, name);
}
 
Example #16
Source File: MBeanOperationInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static MBeanParameterInfo[] parameters(Class<?>[] classes,
                                       Annotation[][] annots) {
    final MBeanParameterInfo[] params =
        new MBeanParameterInfo[classes.length];
    assert(classes.length == annots.length);

    for (int i = 0; i < classes.length; i++) {
        Descriptor d = Introspector.descriptorForAnnotations(annots[i]);
        final String pn = "p" + (i + 1);
        params[i] =
            new MBeanParameterInfo(pn, classes[i].getName(), "", d);
    }

    return params;
}
 
Example #17
Source File: Monitor.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
Comparable<?> getComparableFromAttribute(ObjectName object,
                                         String attribute,
                                         Object value)
    throws AttributeNotFoundException {
    if (isComplexTypeAttribute) {
        Object v = value;
        for (String attr : remainingAttributes)
            v = Introspector.elementFromComplex(v, attr);
        return (Comparable<?>) v;
    } else {
        return (Comparable<?>) value;
    }
}
 
Example #18
Source File: JMX.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Centralised M(X)Bean proxy creation code
 * @param connection {@linkplain MBeanServerConnection} to use
 * @param objectName M(X)Bean object name
 * @param interfaceClass M(X)Bean interface class
 * @param notificationEmitter Is a notification emitter?
 * @param isMXBean Is an MXBean?
 * @return Returns an M(X)Bean proxy generated for the provided interface class
 * @throws SecurityException
 * @throws IllegalArgumentException
 */
private static <T> T createProxy(MBeanServerConnection connection,
                                 ObjectName objectName,
                                 Class<T> interfaceClass,
                                 boolean notificationEmitter,
                                 boolean isMXBean) {

    try {
        if (isMXBean) {
            // Check interface for MXBean compliance
            Introspector.testComplianceMXBeanInterface(interfaceClass);
        } else {
            // Check interface for MBean compliance
            Introspector.testComplianceMBeanInterface(interfaceClass);
        }
    } catch (NotCompliantMBeanException e) {
        throw new IllegalArgumentException(e);
    }

    InvocationHandler handler = new MBeanServerInvocationHandler(
            connection, objectName, isMXBean);
    final Class<?>[] interfaces;
    if (notificationEmitter) {
        interfaces =
            new Class<?>[] {interfaceClass, NotificationEmitter.class};
    } else
        interfaces = new Class<?>[] {interfaceClass};

    Object proxy = Proxy.newProxyInstance(
            interfaceClass.getClassLoader(),
            interfaces,
            handler);
    return interfaceClass.cast(proxy);
}
 
Example #19
Source File: MBeanOperationInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static MBeanParameterInfo[] parameters(Class<?>[] classes,
                                       Annotation[][] annots) {
    final MBeanParameterInfo[] params =
        new MBeanParameterInfo[classes.length];
    assert(classes.length == annots.length);

    for (int i = 0; i < classes.length; i++) {
        Descriptor d = Introspector.descriptorForAnnotations(annots[i]);
        final String pn = "p" + (i + 1);
        params[i] =
            new MBeanParameterInfo(pn, classes[i].getName(), "", d);
    }

    return params;
}
 
Example #20
Source File: Monitor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
Comparable<?> getComparableFromAttribute(ObjectName object,
                                         String attribute,
                                         Object value)
    throws AttributeNotFoundException {
    if (isComplexTypeAttribute) {
        Object v = value;
        for (String attr : remainingAttributes)
            v = Introspector.elementFromComplex(v, attr);
        return (Comparable<?>) v;
    } else {
        return (Comparable<?>) value;
    }
}
 
Example #21
Source File: GreetingMBeanIntrospectionBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws NotCompliantMBeanException {
    // 获取 Greeting 的 MBeanInfo
    MBeanInfo mBeanInfo = Introspector.testCompliance(Greeting.class);
    printf("Greeting 的 MBeanInfo 详情:");
    printf("MBeanAttributeInfo[]:%s", Arrays.asList(mBeanInfo.getAttributes()));
    printf("MBeanOperationInfo[]:%s", Arrays.asList(mBeanInfo.getOperations()));
    printf("MBeanConstructorInfo[]:%s", Arrays.asList(mBeanInfo.getConstructors()));
    printf("MBeanNotificationInfo[]:%s", Arrays.asList(mBeanInfo.getNotifications()));
}
 
Example #22
Source File: StandardMBean.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Make a DynamicMBean out of <var>implementation</var>, using the
 * specified <var>mbeanInterface</var> class.
 * @param implementation The implementation of this MBean.
 *        If <code>null</code>, and null implementation is allowed,
 *        then the implementation is assumed to be <var>this</var>.
 * @param mbeanInterface The Management Interface exported by this
 *        MBean's implementation. If <code>null</code>, then this
 *        object will use standard JMX design pattern to determine
 *        the management interface associated with the given
 *        implementation.
 * @param nullImplementationAllowed <code>true</code> if a null
 *        implementation is allowed. If null implementation is allowed,
 *        and a null implementation is passed, then the implementation
 *        is assumed to be <var>this</var>.
 * @exception IllegalArgumentException if the given
 *    <var>implementation</var> is null, and null is not allowed.
 **/
private <T> void construct(T implementation, Class<T> mbeanInterface,
                           boolean nullImplementationAllowed,
                           boolean isMXBean)
                           throws NotCompliantMBeanException {
    if (implementation == null) {
        // Have to use (T)this rather than mbeanInterface.cast(this)
        // because mbeanInterface might be null.
        if (nullImplementationAllowed)
            implementation = Util.<T>cast(this);
        else throw new IllegalArgumentException("implementation is null");
    }
    if (isMXBean) {
        if (mbeanInterface == null) {
            mbeanInterface = Util.cast(Introspector.getMXBeanInterface(
                    implementation.getClass()));
        }
        this.mbean = new MXBeanSupport(implementation, mbeanInterface);
    } else {
        if (mbeanInterface == null) {
            mbeanInterface = Util.cast(Introspector.getStandardMBeanInterface(
                    implementation.getClass()));
        }
        this.mbean =
                new StandardMBeanSupport(implementation, mbeanInterface);
    }
}
 
Example #23
Source File: JMX.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Centralised M(X)Bean proxy creation code
 * @param connection {@linkplain MBeanServerConnection} to use
 * @param objectName M(X)Bean object name
 * @param interfaceClass M(X)Bean interface class
 * @param notificationEmitter Is a notification emitter?
 * @param isMXBean Is an MXBean?
 * @return Returns an M(X)Bean proxy generated for the provided interface class
 * @throws SecurityException
 * @throws IllegalArgumentException
 */
private static <T> T createProxy(MBeanServerConnection connection,
                                 ObjectName objectName,
                                 Class<T> interfaceClass,
                                 boolean notificationEmitter,
                                 boolean isMXBean) {

    try {
        if (isMXBean) {
            // Check interface for MXBean compliance
            Introspector.testComplianceMXBeanInterface(interfaceClass);
        } else {
            // Check interface for MBean compliance
            Introspector.testComplianceMBeanInterface(interfaceClass);
        }
    } catch (NotCompliantMBeanException e) {
        throw new IllegalArgumentException(e);
    }

    InvocationHandler handler = new MBeanServerInvocationHandler(
            connection, objectName, isMXBean);
    final Class<?>[] interfaces;
    if (notificationEmitter) {
        interfaces =
            new Class<?>[] {interfaceClass, NotificationEmitter.class};
    } else
        interfaces = new Class<?>[] {interfaceClass};

    Object proxy = Proxy.newProxyInstance(
            interfaceClass.getClassLoader(),
            interfaces,
            handler);
    return interfaceClass.cast(proxy);
}
 
Example #24
Source File: JMX.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Centralised M(X)Bean proxy creation code
 * @param connection {@linkplain MBeanServerConnection} to use
 * @param objectName M(X)Bean object name
 * @param interfaceClass M(X)Bean interface class
 * @param notificationEmitter Is a notification emitter?
 * @param isMXBean Is an MXBean?
 * @return Returns an M(X)Bean proxy generated for the provided interface class
 * @throws SecurityException
 * @throws IllegalArgumentException
 */
private static <T> T createProxy(MBeanServerConnection connection,
                                 ObjectName objectName,
                                 Class<T> interfaceClass,
                                 boolean notificationEmitter,
                                 boolean isMXBean) {

    try {
        if (isMXBean) {
            // Check interface for MXBean compliance
            Introspector.testComplianceMXBeanInterface(interfaceClass);
        } else {
            // Check interface for MBean compliance
            Introspector.testComplianceMBeanInterface(interfaceClass);
        }
    } catch (NotCompliantMBeanException e) {
        throw new IllegalArgumentException(e);
    }

    InvocationHandler handler = new MBeanServerInvocationHandler(
            connection, objectName, isMXBean);
    final Class<?>[] interfaces;
    if (notificationEmitter) {
        interfaces =
            new Class<?>[] {interfaceClass, NotificationEmitter.class};
    } else
        interfaces = new Class<?>[] {interfaceClass};

    Object proxy = Proxy.newProxyInstance(
            interfaceClass.getClassLoader(),
            interfaces,
            handler);
    return interfaceClass.cast(proxy);
}
 
Example #25
Source File: StandardMBean.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Make a DynamicMBean out of <var>implementation</var>, using the
 * specified <var>mbeanInterface</var> class.
 * @param implementation The implementation of this MBean.
 *        If <code>null</code>, and null implementation is allowed,
 *        then the implementation is assumed to be <var>this</var>.
 * @param mbeanInterface The Management Interface exported by this
 *        MBean's implementation. If <code>null</code>, then this
 *        object will use standard JMX design pattern to determine
 *        the management interface associated with the given
 *        implementation.
 * @param nullImplementationAllowed <code>true</code> if a null
 *        implementation is allowed. If null implementation is allowed,
 *        and a null implementation is passed, then the implementation
 *        is assumed to be <var>this</var>.
 * @exception IllegalArgumentException if the given
 *    <var>implementation</var> is null, and null is not allowed.
 **/
private <T> void construct(T implementation, Class<T> mbeanInterface,
                           boolean nullImplementationAllowed,
                           boolean isMXBean)
                           throws NotCompliantMBeanException {
    if (implementation == null) {
        // Have to use (T)this rather than mbeanInterface.cast(this)
        // because mbeanInterface might be null.
        if (nullImplementationAllowed)
            implementation = Util.<T>cast(this);
        else throw new IllegalArgumentException("implementation is null");
    }
    if (isMXBean) {
        if (mbeanInterface == null) {
            mbeanInterface = Util.cast(Introspector.getMXBeanInterface(
                    implementation.getClass()));
        }
        this.mbean = new MXBeanSupport(implementation, mbeanInterface);
    } else {
        if (mbeanInterface == null) {
            mbeanInterface = Util.cast(Introspector.getStandardMBeanInterface(
                    implementation.getClass()));
        }
        this.mbean =
                new StandardMBeanSupport(implementation, mbeanInterface);
    }
}
 
Example #26
Source File: JMX.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Centralised M(X)Bean proxy creation code
 * @param connection {@linkplain MBeanServerConnection} to use
 * @param objectName M(X)Bean object name
 * @param interfaceClass M(X)Bean interface class
 * @param notificationEmitter Is a notification emitter?
 * @param isMXBean Is an MXBean?
 * @return Returns an M(X)Bean proxy generated for the provided interface class
 * @throws SecurityException
 * @throws IllegalArgumentException
 */
private static <T> T createProxy(MBeanServerConnection connection,
                                 ObjectName objectName,
                                 Class<T> interfaceClass,
                                 boolean notificationEmitter,
                                 boolean isMXBean) {

    try {
        if (isMXBean) {
            // Check interface for MXBean compliance
            Introspector.testComplianceMXBeanInterface(interfaceClass);
        } else {
            // Check interface for MBean compliance
            Introspector.testComplianceMBeanInterface(interfaceClass);
        }
    } catch (NotCompliantMBeanException e) {
        throw new IllegalArgumentException(e);
    }

    InvocationHandler handler = new MBeanServerInvocationHandler(
            connection, objectName, isMXBean);
    final Class<?>[] interfaces;
    if (notificationEmitter) {
        interfaces =
            new Class<?>[] {interfaceClass, NotificationEmitter.class};
    } else
        interfaces = new Class<?>[] {interfaceClass};

    Object proxy = Proxy.newProxyInstance(
            interfaceClass.getClassLoader(),
            interfaces,
            handler);
    return interfaceClass.cast(proxy);
}
 
Example #27
Source File: JMX.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Centralised M(X)Bean proxy creation code
 * @param connection {@linkplain MBeanServerConnection} to use
 * @param objectName M(X)Bean object name
 * @param interfaceClass M(X)Bean interface class
 * @param notificationEmitter Is a notification emitter?
 * @param isMXBean Is an MXBean?
 * @return Returns an M(X)Bean proxy generated for the provided interface class
 * @throws SecurityException
 * @throws IllegalArgumentException
 */
private static <T> T createProxy(MBeanServerConnection connection,
                                 ObjectName objectName,
                                 Class<T> interfaceClass,
                                 boolean notificationEmitter,
                                 boolean isMXBean) {

    try {
        if (isMXBean) {
            // Check interface for MXBean compliance
            Introspector.testComplianceMXBeanInterface(interfaceClass);
        } else {
            // Check interface for MBean compliance
            Introspector.testComplianceMBeanInterface(interfaceClass);
        }
    } catch (NotCompliantMBeanException e) {
        throw new IllegalArgumentException(e);
    }

    InvocationHandler handler = new MBeanServerInvocationHandler(
            connection, objectName, isMXBean);
    final Class<?>[] interfaces;
    if (notificationEmitter) {
        interfaces =
            new Class<?>[] {interfaceClass, NotificationEmitter.class};
    } else
        interfaces = new Class<?>[] {interfaceClass};

    Object proxy = Proxy.newProxyInstance(
            interfaceClass.getClassLoader(),
            interfaces,
            handler);
    return interfaceClass.cast(proxy);
}
 
Example #28
Source File: StandardMBean.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Make a DynamicMBean out of <var>implementation</var>, using the
 * specified <var>mbeanInterface</var> class.
 * @param implementation The implementation of this MBean.
 *        If <code>null</code>, and null implementation is allowed,
 *        then the implementation is assumed to be <var>this</var>.
 * @param mbeanInterface The Management Interface exported by this
 *        MBean's implementation. If <code>null</code>, then this
 *        object will use standard JMX design pattern to determine
 *        the management interface associated with the given
 *        implementation.
 * @param nullImplementationAllowed <code>true</code> if a null
 *        implementation is allowed. If null implementation is allowed,
 *        and a null implementation is passed, then the implementation
 *        is assumed to be <var>this</var>.
 * @exception IllegalArgumentException if the given
 *    <var>implementation</var> is null, and null is not allowed.
 **/
private <T> void construct(T implementation, Class<T> mbeanInterface,
                           boolean nullImplementationAllowed,
                           boolean isMXBean)
                           throws NotCompliantMBeanException {
    if (implementation == null) {
        // Have to use (T)this rather than mbeanInterface.cast(this)
        // because mbeanInterface might be null.
        if (nullImplementationAllowed)
            implementation = Util.<T>cast(this);
        else throw new IllegalArgumentException("implementation is null");
    }
    if (isMXBean) {
        if (mbeanInterface == null) {
            mbeanInterface = Util.cast(Introspector.getMXBeanInterface(
                    implementation.getClass()));
        }
        this.mbean = new MXBeanSupport(implementation, mbeanInterface);
    } else {
        if (mbeanInterface == null) {
            mbeanInterface = Util.cast(Introspector.getStandardMBeanInterface(
                    implementation.getClass()));
        }
        this.mbean =
                new StandardMBeanSupport(implementation, mbeanInterface);
    }
}
 
Example #29
Source File: MBeanOperationInfo.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static MBeanParameterInfo[] parameters(Class<?>[] classes,
                                       Annotation[][] annots) {
    final MBeanParameterInfo[] params =
        new MBeanParameterInfo[classes.length];
    assert(classes.length == annots.length);

    for (int i = 0; i < classes.length; i++) {
        Descriptor d = Introspector.descriptorForAnnotations(annots[i]);
        final String pn = "p" + (i + 1);
        params[i] =
            new MBeanParameterInfo(pn, classes[i].getName(), "", d);
    }

    return params;
}
 
Example #30
Source File: Monitor.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
Comparable<?> getComparableFromAttribute(ObjectName object,
                                         String attribute,
                                         Object value)
    throws AttributeNotFoundException {
    if (isComplexTypeAttribute) {
        Object v = value;
        for (String attr : remainingAttributes)
            v = Introspector.elementFromComplex(v, attr);
        return (Comparable<?>) v;
    } else {
        return (Comparable<?>) value;
    }
}