Search in sources :

Example 16 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method getNewMBeanClassName.

private static String getNewMBeanClassName(Object mbeanToRegister) throws NotCompliantMBeanException {
    if (mbeanToRegister instanceof DynamicMBean) {
        DynamicMBean mbean = (DynamicMBean) mbeanToRegister;
        final String name;
        try {
            name = mbean.getMBeanInfo().getClassName();
        } catch (Exception e) {
            // Includes case where getMBeanInfo() returns null
            NotCompliantMBeanException ncmbe = new NotCompliantMBeanException("Bad getMBeanInfo()");
            ncmbe.initCause(e);
            throw ncmbe;
        }
        if (name == null) {
            final String msg = "MBeanInfo has null class name";
            throw new NotCompliantMBeanException(msg);
        }
        return name;
    } else
        return mbeanToRegister.getClass().getName();
}
Also used : DynamicMBean(javax.management.DynamicMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) 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 17 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method getClassLoaderFor.

/**
     * <p>Return the {@link java.lang.ClassLoader} that was used for
     * loading the class of the named MBean.
     * @param mbeanName The ObjectName of the MBean.
     * @return The ClassLoader used for that MBean.
     * @exception InstanceNotFoundException if the named MBean is not found.
     */
public ClassLoader getClassLoaderFor(ObjectName mbeanName) throws InstanceNotFoundException {
    DynamicMBean instance = getMBean(mbeanName);
    checkMBeanPermission(instance, null, mbeanName, "getClassLoaderFor");
    return getResource(instance).getClass().getClassLoader();
}
Also used : DynamicMBean(javax.management.DynamicMBean)

Example 18 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method invoke.

public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws InstanceNotFoundException, MBeanException, ReflectionException {
    name = nonDefaultDomain(name);
    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, operationName, name, "invoke");
    try {
        return instance.invoke(operationName, params, signature);
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean)

Example 19 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method removeNotificationListener.

private void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback, boolean removeAll) throws InstanceNotFoundException, ListenerNotFoundException {
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "removeNotificationListener", "ObjectName = " + name);
    }
    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, null, name, "removeNotificationListener");
    /* We could simplify the code by assigning broadcaster after
           assigning listenerWrapper, but that would change the error
           behavior when both the broadcaster and the listener are
           erroneous.  */
    Class<? extends NotificationBroadcaster> reqClass = removeAll ? NotificationBroadcaster.class : NotificationEmitter.class;
    NotificationBroadcaster broadcaster = getNotificationBroadcaster(name, instance, reqClass);
    NotificationListener listenerWrapper = getListenerWrapper(listener, name, instance, false);
    if (listenerWrapper == null)
        throw new ListenerNotFoundException("Unknown listener");
    if (removeAll)
        broadcaster.removeNotificationListener(listenerWrapper);
    else {
        NotificationEmitter emitter = (NotificationEmitter) broadcaster;
        emitter.removeNotificationListener(listenerWrapper, filter, handback);
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) NotificationEmitter(javax.management.NotificationEmitter) NotificationBroadcaster(javax.management.NotificationBroadcaster) ListenerNotFoundException(javax.management.ListenerNotFoundException) NotificationListener(javax.management.NotificationListener)

Example 20 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method getAttributes.

public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException {
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occurred trying to invoke the getter on the MBean");
    }
    if (attributes == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attributes cannot be null"), "Exception occurred trying to invoke the getter on the MBean");
    }
    name = nonDefaultDomain(name);
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "getAttributes", "ObjectName = " + name);
    }
    final DynamicMBean instance = getMBean(name);
    final String[] allowedAttributes;
    final SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        allowedAttributes = attributes;
    else {
        final String classname = getClassName(instance);
        // Check if the caller has the right to invoke 'getAttribute'
        //
        checkMBeanPermission(classname, null, name, "getAttribute");
        // Check if the caller has the right to invoke 'getAttribute'
        // on each specific attribute
        //
        List<String> allowedList = new ArrayList<String>(attributes.length);
        for (String attr : attributes) {
            try {
                checkMBeanPermission(classname, attr, name, "getAttribute");
                allowedList.add(attr);
            } catch (SecurityException e) {
            // OK: Do not add this attribute to the list
            }
        }
        allowedAttributes = allowedList.toArray(new String[allowedList.size()]);
    }
    try {
        return instance.getAttributes(allowedAttributes);
    } catch (Throwable t) {
        rethrow(t);
        throw new AssertionError();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) ArrayList(java.util.ArrayList) RuntimeOperationsException(javax.management.RuntimeOperationsException)

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