Search in sources :

Example 56 with ObjectInstance

use of javax.management.ObjectInstance in project pulsar by yahoo.

the class MBeanStatsGenerator method generate.

private Collection<Metrics> generate() {
    List<Metrics> metricsCollection = new ArrayList<Metrics>();
    @SuppressWarnings("unchecked") Set<ObjectInstance> instances = mbs.queryMBeans(null, null);
    for (ObjectInstance instance : instances) {
        String beanName = instance.getObjectName().toString();
        // skip GC MBean to avoid recursion
        if (beanName.startsWith("java.lang:type=GarbageCollector")) {
            continue;
        }
        Metrics metrics = convert(instance);
        if (metrics != null) {
            metricsCollection.add(metrics);
        }
    }
    return metricsCollection;
}
Also used : ArrayList(java.util.ArrayList) ObjectInstance(javax.management.ObjectInstance)

Example 57 with ObjectInstance

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

the class ServerNotifForwarder method checkMBeanPermission.

static void checkMBeanPermission(final MBeanServer mbs, final ObjectName name, final String actions) throws InstanceNotFoundException, SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        AccessControlContext acc = AccessController.getContext();
        ObjectInstance oi;
        try {
            oi = AccessController.doPrivileged(new PrivilegedExceptionAction<ObjectInstance>() {

                public ObjectInstance run() throws InstanceNotFoundException {
                    return mbs.getObjectInstance(name);
                }
            });
        } catch (PrivilegedActionException e) {
            throw (InstanceNotFoundException) extractException(e);
        }
        String classname = oi.getClassName();
        MBeanPermission perm = new MBeanPermission(classname, null, name, actions);
        sm.checkPermission(perm, acc);
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedActionException(java.security.PrivilegedActionException) MBeanPermission(javax.management.MBeanPermission) ObjectInstance(javax.management.ObjectInstance) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 58 with ObjectInstance

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

the class DefaultMBeanServerInterceptor method registerDynamicMBean.

private ObjectInstance registerDynamicMBean(String classname, DynamicMBean mbean, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    name = nonDefaultDomain(name);
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "registerMBean", "ObjectName = " + name);
    }
    ObjectName logicalName = preRegister(mbean, server, name);
    // preRegister returned successfully, so from this point on we
    // must call postRegister(false) if there is any problem.
    boolean registered = false;
    boolean registerFailed = false;
    ResourceContext context = null;
    try {
        if (mbean instanceof DynamicMBean2) {
            try {
                ((DynamicMBean2) mbean).preRegister2(server, logicalName);
                // until we succeed
                registerFailed = true;
            } catch (Exception e) {
                if (e instanceof RuntimeException)
                    throw (RuntimeException) e;
                if (e instanceof InstanceAlreadyExistsException)
                    throw (InstanceAlreadyExistsException) e;
                throw new RuntimeException(e);
            }
        }
        if (logicalName != name && logicalName != null) {
            logicalName = ObjectName.getInstance(nonDefaultDomain(logicalName));
        }
        checkMBeanPermission(classname, null, logicalName, "registerMBean");
        if (logicalName == null) {
            final RuntimeException wrapped = new IllegalArgumentException("No object name specified");
            throw new RuntimeOperationsException(wrapped, "Exception occurred trying to register the MBean");
        }
        final Object resource = getResource(mbean);
        // Register the MBean with the repository.
        // Returns the resource context that was used.
        // The returned context does nothing for regular MBeans.
        // For ClassLoader MBeans the context makes it possible to register these
        // objects with the appropriate framework artifacts, such as
        // the CLR, from within the repository lock.
        // In case of success, we also need to call context.done() at the
        // end of this method.
        //
        context = registerWithRepository(resource, mbean, logicalName);
        registerFailed = false;
        registered = true;
    } finally {
        try {
            postRegister(logicalName, mbean, registered, registerFailed);
        } finally {
            if (registered && context != null)
                context.done();
        }
    }
    return new ObjectInstance(logicalName, classname);
}
Also used : JMRuntimeException(javax.management.JMRuntimeException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) 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) ObjectName(javax.management.ObjectName) DynamicMBean2(com.sun.jmx.mbeanserver.DynamicMBean2) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 59 with ObjectInstance

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

the class DefaultMBeanServerInterceptor method queryMBeans.

public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        // Check if the caller has the right to invoke 'queryMBeans'
        //
        checkMBeanPermission((String) null, null, null, "queryMBeans");
        // Perform query without "query".
        //
        Set<ObjectInstance> list = queryMBeansImpl(name, null);
        // Check if the caller has the right to invoke 'queryMBeans'
        // on each specific classname/objectname in the list.
        //
        Set<ObjectInstance> allowedList = new HashSet<ObjectInstance>(list.size());
        for (ObjectInstance oi : list) {
            try {
                checkMBeanPermission(oi.getClassName(), null, oi.getObjectName(), "queryMBeans");
                allowedList.add(oi);
            } catch (SecurityException e) {
            // OK: Do not add this ObjectInstance to the list
            }
        }
        //
        return filterListOfObjectInstances(allowedList, query);
    } else {
        //
        return queryMBeansImpl(name, query);
    }
}
Also used : ObjectInstance(javax.management.ObjectInstance) HashSet(java.util.HashSet)

Example 60 with ObjectInstance

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

the class DefaultMBeanServerInterceptor method getObjectInstance.

public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException {
    name = nonDefaultDomain(name);
    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, null, name, "getObjectInstance");
    final String className = getClassName(instance);
    return new ObjectInstance(name, className);
}
Also used : DynamicMBean(javax.management.DynamicMBean) ObjectInstance(javax.management.ObjectInstance)

Aggregations

ObjectInstance (javax.management.ObjectInstance)75 ObjectName (javax.management.ObjectName)36 Test (org.junit.Test)27 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 MBeanServer (javax.management.MBeanServer)12 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)10 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)9 Result (com.googlecode.jmxtrans.model.Result)9 HashSet (java.util.HashSet)7 Attribute (javax.management.Attribute)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 HashMap (java.util.HashMap)4 AttributeList (javax.management.AttributeList)4 MBeanException (javax.management.MBeanException)4 MBeanServerConnection (javax.management.MBeanServerConnection)4 ReflectionException (javax.management.ReflectionException)4