Search in sources :

Example 31 with DynamicMBean

use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.

the class DefaultMBeanServerInterceptor method isInstanceOf.

public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException {
    final DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, null, name, "isInstanceOf");
    try {
        Object resource = getResource(instance);
        final String resourceClassName = (resource instanceof DynamicMBean) ? getClassName((DynamicMBean) resource) : resource.getClass().getName();
        if (resourceClassName.equals(className))
            return true;
        final ClassLoader cl = resource.getClass().getClassLoader();
        final Class<?> classNameClass = Class.forName(className, false, cl);
        if (classNameClass.isInstance(resource))
            return true;
        final Class<?> resourceClass = Class.forName(resourceClassName, false, cl);
        return classNameClass.isAssignableFrom(resourceClass);
    } catch (Exception x) {
        /* Could be SecurityException or ClassNotFoundException */
        if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
            MBEANSERVER_LOGGER.logp(Level.FINEST, DefaultMBeanServerInterceptor.class.getName(), "isInstanceOf", "Exception calling isInstanceOf", x);
        }
        return false;
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) NamedObject(com.sun.jmx.mbeanserver.NamedObject) IntrospectionException(javax.management.IntrospectionException) OperationsException(javax.management.OperationsException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ReflectionException(javax.management.ReflectionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RuntimeMBeanException(javax.management.RuntimeMBeanException) RuntimeErrorException(javax.management.RuntimeErrorException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException)

Example 32 with DynamicMBean

use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.

the class DefaultMBeanServerInterceptor method setAttributes.

public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException {
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
    }
    if (attributes == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("AttributeList  cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
    }
    name = nonDefaultDomain(name);
    final DynamicMBean instance = getMBean(name);
    final AttributeList allowedAttributes;
    final SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        allowedAttributes = attributes;
    else {
        String classname = getClassName(instance);
        // Check if the caller has the right to invoke 'setAttribute'
        //
        checkMBeanPermission(classname, null, name, "setAttribute");
        // Check if the caller has the right to invoke 'setAttribute'
        // on each specific attribute
        //
        allowedAttributes = new AttributeList(attributes.size());
        for (Attribute attribute : attributes.asList()) {
            try {
                checkMBeanPermission(classname, attribute.getName(), name, "setAttribute");
                allowedAttributes.add(attribute);
            } catch (SecurityException e) {
            // OK: Do not add this attribute to the list
            }
        }
    }
    try {
        return instance.setAttributes(allowedAttributes);
    } catch (Throwable t) {
        rethrow(t);
        throw new AssertionError();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 33 with DynamicMBean

use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.

the class DefaultMBeanServerInterceptor method getListener.

private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException {
    // ----------------
    // Get listener object
    // ----------------
    DynamicMBean instance;
    try {
        instance = getMBean(listener);
    } catch (InstanceNotFoundException e) {
        throw EnvHelp.initCause(new ListenerNotFoundException(e.getMessage()), e);
    }
    Object resource = getResource(instance);
    if (!(resource instanceof NotificationListener)) {
        final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName());
        final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName();
        throw new RuntimeOperationsException(exc, msg);
    }
    return (NotificationListener) resource;
}
Also used : DynamicMBean(javax.management.DynamicMBean) JMRuntimeException(javax.management.JMRuntimeException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ListenerNotFoundException(javax.management.ListenerNotFoundException) NamedObject(com.sun.jmx.mbeanserver.NamedObject) NotificationListener(javax.management.NotificationListener) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 34 with DynamicMBean

use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.

the class DefaultMBeanServerInterceptor method addNotificationListener.

public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException {
    // ------------------------------
    // ------------------------------
    // ----------------
    // Get listener object
    // ----------------
    DynamicMBean instance = getMBean(listener);
    Object resource = getResource(instance);
    if (!(resource instanceof NotificationListener)) {
        throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface");
    }
    // ----------------
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener);
    }
    server.addNotificationListener(name, (NotificationListener) resource, filter, handback);
}
Also used : DynamicMBean(javax.management.DynamicMBean) NamedObject(com.sun.jmx.mbeanserver.NamedObject) NotificationListener(javax.management.NotificationListener) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 35 with DynamicMBean

use of javax.management.DynamicMBean in project jdk8u_jdk by JetBrains.

the class DefaultMBeanServerInterceptor method getMBeanInfo.

public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException {
    // ------------------------------
    // ------------------------------
    DynamicMBean moi = getMBean(name);
    final MBeanInfo mbi;
    try {
        mbi = moi.getMBeanInfo();
    } catch (RuntimeMBeanException e) {
        throw e;
    } catch (RuntimeErrorException e) {
        throw e;
    } catch (RuntimeException e) {
        throw new RuntimeMBeanException(e, "getMBeanInfo threw RuntimeException");
    } catch (Error e) {
        throw new RuntimeErrorException(e, "getMBeanInfo threw Error");
    }
    if (mbi == null)
        throw new JMRuntimeException("MBean " + name + "has no MBeanInfo");
    checkMBeanPermission(mbi.getClassName(), null, name, "getMBeanInfo");
    return mbi;
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) DynamicMBean(javax.management.DynamicMBean) JMRuntimeException(javax.management.JMRuntimeException) MBeanInfo(javax.management.MBeanInfo) RuntimeErrorException(javax.management.RuntimeErrorException) JMRuntimeException(javax.management.JMRuntimeException)

Aggregations

DynamicMBean (javax.management.DynamicMBean)37 MBeanException (javax.management.MBeanException)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)13 ObjectName (javax.management.ObjectName)10 AttributeNotFoundException (javax.management.AttributeNotFoundException)8 InstanceNotFoundException (javax.management.InstanceNotFoundException)8 ListenerNotFoundException (javax.management.ListenerNotFoundException)8 MalformedObjectNameException (javax.management.MalformedObjectNameException)8 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 RuntimeErrorException (javax.management.RuntimeErrorException)7 ManagedBean (org.apache.tomcat.util.modeler.ManagedBean)7 NamedObject (com.sun.jmx.mbeanserver.NamedObject)6 ReflectionException (javax.management.ReflectionException)6 JMRuntimeException (javax.management.JMRuntimeException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)4 NotificationListener (javax.management.NotificationListener)4 RuntimeMBeanException (javax.management.RuntimeMBeanException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3