Search in sources :

Example 11 with DynamicMBean

use of javax.management.DynamicMBean in project sling by apache.

the class JmxAdjustableStatusForTestingIT method invokeMBean.

private void invokeMBean(String operation, Object[] args, String[] signature) throws Exception {
    ServiceReference[] serviceReference = bundleContext.getServiceReferences(DynamicMBean.class.getName(), "(jmx.objectname=org.apache.sling.healthcheck:type=AdjustableHealthCheckForTesting)");
    DynamicMBean mBean = (DynamicMBean) bundleContext.getService(serviceReference[0]);
    mBean.invoke(operation, args, signature);
}
Also used : DynamicMBean(javax.management.DynamicMBean) ServiceReference(org.osgi.framework.ServiceReference)

Example 12 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method exclusiveUnregisterMBean.

private void exclusiveUnregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException {
    DynamicMBean instance = getMBean(name);
    // may throw InstanceNotFoundException
    checkMBeanPermission(instance, null, name, "unregisterMBean");
    if (instance instanceof MBeanRegistration)
        preDeregisterInvoke((MBeanRegistration) instance);
    final Object resource = getResource(instance);
    // Unregisters the MBean from the repository.
    // Returns the resource context that was used.
    // The returned context does nothing for regular MBeans.
    // For ClassLoader MBeans and JMXNamespace (and JMXDomain)
    // MBeans - the context makes it possible to unregister these
    // objects from the appropriate framework artifacts, such as
    // the CLR or the dispatcher, from within the repository lock.
    // In case of success, we also need to call context.done() at the
    // end of this method.
    //
    final ResourceContext context = unregisterFromRepository(resource, instance, name);
    try {
        if (instance instanceof MBeanRegistration)
            postDeregisterInvoke(name, (MBeanRegistration) instance);
    } finally {
        context.done();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) NamedObject(com.sun.jmx.mbeanserver.NamedObject) MBeanRegistration(javax.management.MBeanRegistration)

Example 13 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method objectInstancesFromFilteredNamedObjects.

/**
     * Applies the specified queries to the set of NamedObjects.
     */
private Set<ObjectInstance> objectInstancesFromFilteredNamedObjects(Set<NamedObject> list, QueryExp query) {
    Set<ObjectInstance> result = new HashSet<ObjectInstance>();
    // No query ...
    if (query == null) {
        for (NamedObject no : list) {
            final DynamicMBean obj = no.getObject();
            final String className = safeGetClassName(obj);
            result.add(new ObjectInstance(no.getName(), className));
        }
    } else {
        // Access the filter
        MBeanServer oldServer = QueryEval.getMBeanServer();
        query.setMBeanServer(server);
        try {
            for (NamedObject no : list) {
                final DynamicMBean obj = no.getObject();
                boolean res;
                try {
                    res = query.apply(no.getName());
                } catch (Exception e) {
                    res = false;
                }
                if (res) {
                    String className = safeGetClassName(obj);
                    result.add(new ObjectInstance(no.getName(), className));
                }
            }
        } finally {
            /*
                 * query.setMBeanServer is probably
                 * QueryEval.setMBeanServer so put back the old
                 * value.  Since that method uses a ThreadLocal
                 * variable, this code is only needed for the
                 * unusual case where the user creates a custom
                 * QueryExp that calls a nested query on another
                 * MBeanServer.
                 */
            query.setMBeanServer(oldServer);
        }
    }
    return result;
}
Also used : DynamicMBean(javax.management.DynamicMBean) ObjectInstance(javax.management.ObjectInstance) 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) HashSet(java.util.HashSet) MBeanServer(javax.management.MBeanServer)

Example 14 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method getClassLoader.

/**
     * <p>Return the named {@link java.lang.ClassLoader}.
     * @param loaderName The ObjectName of the ClassLoader.
     * @return The named ClassLoader.
     * @exception InstanceNotFoundException if the named ClassLoader
     * is not found.
     */
public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException {
    if (loaderName == null) {
        checkMBeanPermission((String) null, null, null, "getClassLoader");
        return server.getClass().getClassLoader();
    }
    DynamicMBean instance = getMBean(loaderName);
    checkMBeanPermission(instance, null, loaderName, "getClassLoader");
    Object resource = getResource(instance);
    /* Check if the given MBean is a ClassLoader */
    if (!(resource instanceof ClassLoader))
        throw new InstanceNotFoundException(loaderName.toString() + " is not a classloader");
    return (ClassLoader) resource;
}
Also used : DynamicMBean(javax.management.DynamicMBean) InstanceNotFoundException(javax.management.InstanceNotFoundException) NamedObject(com.sun.jmx.mbeanserver.NamedObject)

Example 15 with DynamicMBean

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

the class DefaultMBeanServerInterceptor method setAttribute.

public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, 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 (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
    }
    name = nonDefaultDomain(name);
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "setAttribute", "ObjectName = " + name + ", Attribute = " + attribute.getName());
    }
    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, attribute.getName(), name, "setAttribute");
    try {
        instance.setAttribute(attribute);
    } catch (AttributeNotFoundException e) {
        throw e;
    } catch (InvalidAttributeValueException e) {
        throw e;
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError();
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) AttributeNotFoundException(javax.management.AttributeNotFoundException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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