Search in sources :

Example 81 with MBeanInfo

use of javax.management.MBeanInfo in project tomee by apache.

the class LocalJMXCommand method set.

private void set(final String cmd) {
    final String[] split = cmd.split(" ");
    if (split.length < 2) {
        streamManager.writeErr("you need to specify an attribute, an objectname and a value");
        return;
    }
    final MBeanServer mBeanServer = LocalMBeanServer.get();
    final String newValue = cmd.substring(split[0].length() + split[1].length() + 1).trim();
    try {
        final ObjectName oname = new ObjectName(split[1]);
        final MBeanInfo minfo = mBeanServer.getMBeanInfo(oname);
        final MBeanAttributeInfo[] attrs = minfo.getAttributes();
        String type = String.class.getName();
        for (int i = 0; i < attrs.length; i++) {
            if (attrs[i].getName().equals(split[0])) {
                type = attrs[i].getType();
                break;
            }
        }
        final Object valueObj = PropertyEditors.getValue(type, newValue, Thread.currentThread().getContextClassLoader());
        mBeanServer.setAttribute(oname, new Attribute(split[0], valueObj));
        streamManager.writeOut("done");
    } catch (Exception ex) {
        streamManager.writeOut("Error - " + ex.toString());
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) RuntimeMBeanException(javax.management.RuntimeMBeanException) MalformedObjectNameException(javax.management.MalformedObjectNameException) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 82 with MBeanInfo

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

the class MBeanIntrospector method getClassMBeanInfo.

/**
     * Return the basic MBeanInfo for resources of the given class and
     * per-interface data.  This MBeanInfo might not be the final MBeanInfo
     * for instances of the class, because if the class is a
     * NotificationBroadcaster then each instance gets to decide what
     * MBeanNotificationInfo[] to put in its own MBeanInfo.
     */
final MBeanInfo getClassMBeanInfo(Class<?> resourceClass, PerInterface<M> perInterface) {
    MBeanInfoMap map = getMBeanInfoMap();
    synchronized (map) {
        WeakHashMap<Class<?>, MBeanInfo> intfMap = map.get(resourceClass);
        if (intfMap == null) {
            intfMap = new WeakHashMap<Class<?>, MBeanInfo>();
            map.put(resourceClass, intfMap);
        }
        Class<?> intfClass = perInterface.getMBeanInterface();
        MBeanInfo mbi = intfMap.get(intfClass);
        if (mbi == null) {
            MBeanInfo imbi = perInterface.getMBeanInfo();
            Descriptor descriptor = ImmutableDescriptor.union(imbi.getDescriptor(), getMBeanDescriptor(resourceClass));
            mbi = new MBeanInfo(resourceClass.getName(), imbi.getDescription(), imbi.getAttributes(), findConstructors(resourceClass), imbi.getOperations(), (MBeanNotificationInfo[]) null, descriptor);
            intfMap.put(intfClass, mbi);
        }
        return mbi;
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor)

Example 83 with MBeanInfo

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

the class MBeanIntrospector method getPerInterface.

final PerInterface<M> getPerInterface(Class<?> mbeanInterface) throws NotCompliantMBeanException {
    PerInterfaceMap<M> map = getPerInterfaceMap();
    synchronized (map) {
        WeakReference<PerInterface<M>> wr = map.get(mbeanInterface);
        PerInterface<M> pi = (wr == null) ? null : wr.get();
        if (pi == null) {
            try {
                MBeanAnalyzer<M> analyzer = getAnalyzer(mbeanInterface);
                MBeanInfo mbeanInfo = makeInterfaceMBeanInfo(mbeanInterface, analyzer);
                pi = new PerInterface<M>(mbeanInterface, this, analyzer, mbeanInfo);
                wr = new WeakReference<PerInterface<M>>(pi);
                map.put(mbeanInterface, wr);
            } catch (Exception x) {
                throw Introspector.throwException(mbeanInterface, x);
            }
        }
        return pi;
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) IntrospectionException(javax.management.IntrospectionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ReflectionException(javax.management.ReflectionException)

Example 84 with MBeanInfo

use of javax.management.MBeanInfo in project tomee by apache.

the class ManagedMBean method getMBeanInfo.

public MBeanInfo getMBeanInfo() {
    final List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>(this.attributes);
    final List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>(this.operations);
    for (final Member member : dynamic) {
        try {
            final ManagedCollection managedCollection = member.getAnnotation(ManagedCollection.class);
            final Collection collection = (Collection) member.get();
            for (final Object o : collection) {
                try {
                    final Field field = o.getClass().getDeclaredField(managedCollection.key());
                    field.setAccessible(true);
                    final Object key = field.get(o);
                    final ManagedMBean bean = new ManagedMBean(o, key.toString());
                    Collections.addAll(attributes, bean.getMBeanInfo().getAttributes());
                    Collections.addAll(operations, bean.getMBeanInfo().getOperations());
                    attributesMap.putAll(bean.attributesMap);
                    operationsMap.putAll(bean.operationsMap);
                } catch (final Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
    sort(operations, MBeanFeatureInfoComparator.INSTANCE);
    sort(attributes, MBeanFeatureInfoComparator.INSTANCE);
    if (filterAttributes) {
        final Iterator<MBeanAttributeInfo> iterator = attributes.iterator();
        while (iterator.hasNext()) {
            final MBeanAttributeInfo info = iterator.next();
            if (includes.matcher(info.getName()).matches()) {
                continue;
            }
            if (excludes.matcher(info.getName()).matches()) {
                iterator.remove();
            }
        }
    }
    return new MBeanInfo(this.getClass().getName(), "", attributes.toArray(new MBeanAttributeInfo[attributes.size()]), new MBeanConstructorInfo[0], operations.toArray(new MBeanOperationInfo[operations.size()]), EMPTY_NOTIFICATIONS);
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) AttributeNotFoundException(javax.management.AttributeNotFoundException) ReflectionException(javax.management.ReflectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) Field(java.lang.reflect.Field) Collection(java.util.Collection)

Example 85 with MBeanInfo

use of javax.management.MBeanInfo in project jmxtrans by jmxtrans.

the class TreeWalker2 method walkTree.

public void walkTree(MBeanServerConnection connection, Server server) throws Exception {
    // key here is null, null returns everything!
    Set<ObjectName> mbeans = connection.queryNames(null, null);
    for (ObjectName name : mbeans) {
        MBeanInfo info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attrs = info.getAttributes();
        Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName()).addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, Collections.<String, Object>emptyMap()));
        for (MBeanAttributeInfo attrInfo : attrs) {
            queryBuilder.addAttr(attrInfo.getName());
        }
        Query query = queryBuilder.build();
        try {
            Iterable<Result> results = server.execute(query);
            query.runOutputWritersForQuery(server, results);
        } catch (AttributeNotFoundException anfe) {
            log.error("Error", anfe);
        }
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) Query(com.googlecode.jmxtrans.model.Query) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) StdOutWriter(com.googlecode.jmxtrans.model.output.StdOutWriter) Result(com.googlecode.jmxtrans.model.Result)

Aggregations

MBeanInfo (javax.management.MBeanInfo)154 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)87 ObjectName (javax.management.ObjectName)79 MBeanOperationInfo (javax.management.MBeanOperationInfo)38 MBeanServer (javax.management.MBeanServer)27 Test (org.junit.Test)27 Attribute (javax.management.Attribute)19 ArrayList (java.util.ArrayList)17 IntrospectionException (javax.management.IntrospectionException)16 ReflectionException (javax.management.ReflectionException)16 HashMap (java.util.HashMap)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 IOException (java.io.IOException)12 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)12 MBeanParameterInfo (javax.management.MBeanParameterInfo)12 MBeanServerConnection (javax.management.MBeanServerConnection)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 AttributeList (javax.management.AttributeList)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)9 Descriptor (javax.management.Descriptor)8