Search in sources :

Example 31 with MBeanInfo

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

the class MXBeanInteropTest1 method doOperatingSystemMXBeanTest.

private final int doOperatingSystemMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0;
    System.out.println("---- OperatingSystemMXBean");
    try {
        ObjectName operationName = new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
        MBeanInfo mbInfo = mbsc.getMBeanInfo(operationName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        OperatingSystemMXBean operation = null;
        operation = JMX.newMXBeanProxy(mbsc, operationName, OperatingSystemMXBean.class);
        System.out.println("getArch\t\t" + operation.getArch());
        System.out.println("getAvailableProcessors\t\t" + operation.getAvailableProcessors());
        System.out.println("getName\t\t" + operation.getName());
        System.out.println("getVersion\t\t" + operation.getVersion());
        System.out.println("---- OK\n");
    } catch (Exception e) {
        Utils.printThrowable(e, true);
        errorCount++;
        System.out.println("---- ERROR\n");
    }
    return errorCount;
}
Also used : MBeanInfo(javax.management.MBeanInfo) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) ObjectName(javax.management.ObjectName)

Example 32 with MBeanInfo

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

the class LogStoreProbeHandler method getMBeanValues.

private Map<String, String> getMBeanValues(MBeanServerConnection cnx, ObjectName on, String... attributeNames) throws InstanceNotFoundException, IOException, ReflectionException, IntrospectionException {
    if (attributeNames == null) {
        MBeanInfo info = cnx.getMBeanInfo(on);
        MBeanAttributeInfo[] attributeArray = info.getAttributes();
        int i = 0;
        attributeNames = new String[attributeArray.length];
        for (MBeanAttributeInfo ai : attributeArray) attributeNames[i++] = ai.getName();
    }
    AttributeList attributes = cnx.getAttributes(on, attributeNames);
    Map<String, String> values = new HashMap<String, String>();
    for (javax.management.Attribute attribute : attributes.asList()) {
        Object value = attribute.getValue();
        values.put(attribute.getName(), value == null ? "" : value.toString());
    }
    return values;
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) AttributeList(javax.management.AttributeList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 33 with MBeanInfo

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

the class RegistrableStandardEmitterMBean method getMBeanInfo.

/**
     * @see javax.management.StandardMBean#getMBeanInfo()
     */
public MBeanInfo getMBeanInfo() {
    MBeanInfo mbeanInfo = super.getMBeanInfo();
    if (mbeanInfo != null) {
        MBeanNotificationInfo[] notificationInfo;
        Object impl = getImplementation();
        if (impl instanceof NotificationEmitter) {
            notificationInfo = ((NotificationEmitter) (impl)).getNotificationInfo();
        } else {
            notificationInfo = new MBeanNotificationInfo[0];
        }
        mbeanInfo = new MBeanInfo(mbeanInfo.getClassName(), mbeanInfo.getDescription(), mbeanInfo.getAttributes(), mbeanInfo.getConstructors(), mbeanInfo.getOperations(), notificationInfo);
    }
    return mbeanInfo;
}
Also used : MBeanNotificationInfo(javax.management.MBeanNotificationInfo) NotificationEmitter(javax.management.NotificationEmitter) MBeanInfo(javax.management.MBeanInfo)

Example 34 with MBeanInfo

use of javax.management.MBeanInfo in project lucene-solr by apache.

the class MetricsMap method getMBeanInfo.

@Override
public MBeanInfo getMBeanInfo() {
    ArrayList<MBeanAttributeInfo> attrInfoList = new ArrayList<>();
    Map<String, Object> stats = getValue(true);
    if (useCachedStatsBetweenGetMBeanInfoCalls) {
        cachedValue = stats;
    }
    try {
        stats.forEach((k, v) -> {
            Class type = v.getClass();
            OpenType typeBox = determineType(type);
            if (type.equals(String.class) || typeBox == null) {
                attrInfoList.add(new MBeanAttributeInfo(k, String.class.getName(), null, true, false, false));
            } else {
                attrInfoList.add(new OpenMBeanAttributeInfoSupport(k, k, typeBox, true, false, false));
            }
        });
    } catch (Exception e) {
        // don't log issue if the core is closing
        if (!(SolrException.getRootCause(e) instanceof AlreadyClosedException))
            log.warn("Could not get attributes of MetricsMap: {}", this, e);
    }
    MBeanAttributeInfo[] attrInfoArr = attrInfoList.toArray(new MBeanAttributeInfo[attrInfoList.size()]);
    return new MBeanInfo(getClass().getName(), "MetricsMap", attrInfoArr, null, null, null);
}
Also used : OpenType(javax.management.openmbean.OpenType) MBeanInfo(javax.management.MBeanInfo) ArrayList(java.util.ArrayList) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) AttributeNotFoundException(javax.management.AttributeNotFoundException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) SolrException(org.apache.solr.common.SolrException) ReflectionException(javax.management.ReflectionException) OpenMBeanAttributeInfoSupport(javax.management.openmbean.OpenMBeanAttributeInfoSupport)

Example 35 with MBeanInfo

use of javax.management.MBeanInfo in project jackrabbit-oak by apache.

the class AnnotatedStandardMBeanTest method test.

@Test
public void test() throws Exception {
    MBeanInfo info = server.getMBeanInfo(objectName);
    assertEquals("MBean desc.", info.getDescription());
    MBeanAttributeInfo a0 = findAttribute(info, "Getter");
    assertEquals("getter", a0.getDescription());
    MBeanAttributeInfo a1 = findAttribute(info, "It");
    assertEquals("is", a1.getDescription());
    MBeanAttributeInfo a2 = findAttribute(info, "Setter");
    assertEquals("setter", a2.getDescription());
    MBeanOperationInfo op0 = info.getOperations()[0];
    assertEquals("run", op0.getDescription());
    assertEquals(MBeanOperationInfo.INFO, op0.getImpact());
    MBeanParameterInfo p0 = op0.getSignature()[0];
    assertEquals("timeout", p0.getName());
    assertEquals("how long?", p0.getDescription());
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

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