Search in sources :

Example 16 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project deltaspike by apache.

the class SimpleRegistrationTest method checkMBean.

@Test
public void checkMBean() throws Exception {
    assertEquals(0, myMBean.getCounter());
    myMBean.resetTo(2);
    final ObjectName on = new ObjectName("org.apache.deltaspike:type=MBeans,name=" + MyMBean.class.getName());
    assertTrue(server.isRegistered(on));
    assertEquals(2, server.getAttribute(on, "counter"));
    assertEquals(6, server.invoke(on, "multiply", new Object[] { 3 }, new String[0]));
    myMBean.resetTo(5);
    assertEquals(5, server.getAttribute(on, "counter"));
    assertEquals(20, server.invoke(on, "multiply", new Object[] { 4 }, new String[0]));
    server.setAttribute(on, new Attribute("counter", 10));
    assertEquals(10, myMBean.getCounter());
    final Collection<Notification> notifications = new ArrayList<Notification>();
    server.addNotificationListener(on, new NotificationListener() {

        @Override
        public void handleNotification(final Notification notification, final Object handback) {
            notifications.add(notification);
        }
    }, null, null);
    myMBean.broadcast();
    assertEquals(1, notifications.size());
    assertEquals(10L, notifications.iterator().next().getSequenceNumber());
    MBeanInfo mBeanInfo = server.getMBeanInfo(on);
    Assert.assertNotNull(mBeanInfo);
    MBeanOperationInfo[] operations = mBeanInfo.getOperations();
    Assert.assertNotNull(operations);
    Assert.assertTrue(operations.length > 0);
    Assert.assertTrue("Empty Signature on operation: " + operations[1], operations[1].getSignature().length > 0);
    MBeanParameterInfo parameterInfo = operations[1].getSignature()[0];
    assertEquals("multiplier", parameterInfo.getName());
    assertEquals("the multiplier", parameterInfo.getDescription());
    {
        // table support - through map
        Object table = server.getAttribute(on, "table");
        assertTrue(TabularData.class.isInstance(table));
        final TabularData data = TabularData.class.cast(table);
        assertEquals(1, data.size());
        final CompositeData compositeData = CompositeData.class.cast(data.values().iterator().next());
        assertEquals(2, compositeData.values().size());
        assertEquals("value1", compositeData.get("key1"));
        assertEquals("value2", compositeData.get("key2"));
    }
    {
        // table support - through Table
        Object table = server.getAttribute(on, "table2");
        assertTrue(TabularData.class.isInstance(table));
        final TabularData data = TabularData.class.cast(table);
        assertEquals(2, data.size());
        final Iterator<?> iterator = data.values().iterator();
        {
            final CompositeData compositeData = CompositeData.class.cast(iterator.next());
            assertEquals(3, compositeData.values().size());
            assertEquals("1", compositeData.get("a"));
            assertEquals("2", compositeData.get("b"));
            assertEquals("3", compositeData.get("c"));
        }
        {
            final CompositeData compositeData = CompositeData.class.cast(iterator.next());
            assertEquals(3, compositeData.values().size());
            assertEquals("alpha", compositeData.get("a"));
            assertEquals("beta", compositeData.get("b"));
            assertEquals("gamma", compositeData.get("c"));
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Iterator(java.util.Iterator) NotificationListener(javax.management.NotificationListener) MBeanParameterInfo(javax.management.MBeanParameterInfo) Test(org.junit.Test)

Example 17 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project geode by apache.

the class LocalProcessControllerJUnitTest method testProcessMBean.

@Test
public void testProcessMBean() throws Exception {
    // validate basics of the ProcessMBean
    Set<ObjectName> mbeanNames = this.server.queryNames(objectName, null);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    assertEquals(1, mbeanNames.size());
    final ObjectName name = mbeanNames.iterator().next();
    final MBeanInfo info = this.server.getMBeanInfo(name);
    final MBeanOperationInfo[] operInfo = info.getOperations();
    assertEquals(1, operInfo.length);
    assertEquals("stop", operInfo[0].getName());
    final MBeanAttributeInfo[] attrInfo = info.getAttributes();
    assertEquals(2, attrInfo.length);
    // The order of these attributes is indeterminate
    assertTrue("Pid".equals(attrInfo[0].getName()) || "Process".equals(attrInfo[0].getName()));
    assertTrue("Pid".equals(attrInfo[1].getName()) || "Process".equals(attrInfo[1].getName()));
    assertNotNull(this.server.getAttribute(name, "Pid"));
    assertNotNull(this.server.getAttribute(name, "Process"));
    assertEquals(pid, this.server.getAttribute(name, "Pid"));
    assertEquals(true, this.server.getAttribute(name, "Process"));
    // validate query using only Pid attribute
    QueryExp constraint = Query.eq(Query.attr("Pid"), Query.value(pid));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    // validate query with wrong Pid finds nothing
    constraint = Query.eq(Query.attr("Pid"), Query.value(pid + 1));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertTrue("Found matching mbeans", mbeanNames.isEmpty());
    // validate query using both attributes
    constraint = Query.and(Query.eq(Query.attr("Process"), Query.value(true)), Query.eq(Query.attr("Pid"), Query.value(pid)));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
    // validate query with wrong attribute finds nothing
    constraint = Query.and(Query.eq(Query.attr("Process"), Query.value(false)), Query.eq(Query.attr("Pid"), Query.value(pid)));
    mbeanNames = this.server.queryNames(objectName, constraint);
    assertTrue("Found matching mbeans", mbeanNames.isEmpty());
}
Also used : MBeanInfo(javax.management.MBeanInfo) QueryExp(javax.management.QueryExp) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 18 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo in project ignite by apache.

the class GridMBeanSelfTest method testCorrectMBeanInfo.

/**
     * Tests correct MBean interface.
     *
     * @throws Exception Thrown if test fails.
     */
public void testCorrectMBeanInfo() throws Exception {
    StandardMBean mbean = new IgniteStandardMXBean(new GridMBeanImplementation(), GridMBeanInterface.class);
    MBeanInfo info = mbean.getMBeanInfo();
    assert info.getDescription().equals("MBeanDescription.") == true;
    assert info.getOperations().length == 2;
    for (MBeanOperationInfo opInfo : info.getOperations()) {
        if (opInfo.getDescription().equals("MBeanOperation."))
            assert opInfo.getSignature().length == 2;
        else {
            assert opInfo.getDescription().equals("MBeanSuperOperation.") == true;
            assert opInfo.getSignature().length == 1;
        }
    }
    for (MBeanParameterInfo paramInfo : info.getOperations()[0].getSignature()) {
        if (paramInfo.getName().equals("ignored"))
            assert paramInfo.getDescription().equals("MBeanOperationParameter1.") == true;
        else {
            assert paramInfo.getName().equals("someData") == true;
            assert paramInfo.getDescription().equals("MBeanOperationParameter2.") == true;
        }
    }
    assert info.getAttributes().length == 4 : "Expected 4 attributes but got " + info.getAttributes().length;
    for (MBeanAttributeInfo attrInfo : info.getAttributes()) {
        if (attrInfo.isWritable() == false) {
            assert (attrInfo.getDescription().equals("MBeanReadonlyGetter.") == true || attrInfo.getDescription().equals("MBeanROGetter."));
        } else {
            assert (attrInfo.getDescription().equals("MBeanWritableGetter.") == true || attrInfo.getDescription().equals("MBeanWritableIsGetter."));
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) StandardMBean(javax.management.StandardMBean) IgniteStandardMXBean(org.apache.ignite.internal.mxbean.IgniteStandardMXBean) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 19 with MBeanOperationInfo

use of javax.management.MBeanOperationInfo 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)

Example 20 with MBeanOperationInfo

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

the class ModelMBeanInfoSupport method getDescriptors.

public Descriptor[] getDescriptors(String inDescriptorType) throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, ModelMBeanInfoSupport.class.getName(), "getDescriptors(String)", "Entry");
    }
    if ((inDescriptorType == null) || (inDescriptorType.equals(""))) {
        inDescriptorType = "all";
    }
    // if no descriptors of that type, will return empty array
    //
    final Descriptor[] retList;
    if (inDescriptorType.equalsIgnoreCase(MMB)) {
        retList = new Descriptor[] { modelMBeanDescriptor };
    } else if (inDescriptorType.equalsIgnoreCase(ATTR)) {
        final MBeanAttributeInfo[] attrList = modelMBeanAttributes;
        int numAttrs = 0;
        if (attrList != null)
            numAttrs = attrList.length;
        retList = new Descriptor[numAttrs];
        for (int i = 0; i < numAttrs; i++) {
            retList[i] = (((ModelMBeanAttributeInfo) attrList[i]).getDescriptor());
        }
    } else if (inDescriptorType.equalsIgnoreCase(OPER)) {
        final MBeanOperationInfo[] operList = modelMBeanOperations;
        int numOpers = 0;
        if (operList != null)
            numOpers = operList.length;
        retList = new Descriptor[numOpers];
        for (int i = 0; i < numOpers; i++) {
            retList[i] = (((ModelMBeanOperationInfo) operList[i]).getDescriptor());
        }
    } else if (inDescriptorType.equalsIgnoreCase(CONS)) {
        final MBeanConstructorInfo[] consList = modelMBeanConstructors;
        int numCons = 0;
        if (consList != null)
            numCons = consList.length;
        retList = new Descriptor[numCons];
        for (int i = 0; i < numCons; i++) {
            retList[i] = (((ModelMBeanConstructorInfo) consList[i]).getDescriptor());
        }
    } else if (inDescriptorType.equalsIgnoreCase(NOTF)) {
        final MBeanNotificationInfo[] notifList = modelMBeanNotifications;
        int numNotifs = 0;
        if (notifList != null)
            numNotifs = notifList.length;
        retList = new Descriptor[numNotifs];
        for (int i = 0; i < numNotifs; i++) {
            retList[i] = (((ModelMBeanNotificationInfo) notifList[i]).getDescriptor());
        }
    } else if (inDescriptorType.equalsIgnoreCase(ALL)) {
        final MBeanAttributeInfo[] attrList = modelMBeanAttributes;
        int numAttrs = 0;
        if (attrList != null)
            numAttrs = attrList.length;
        final MBeanOperationInfo[] operList = modelMBeanOperations;
        int numOpers = 0;
        if (operList != null)
            numOpers = operList.length;
        final MBeanConstructorInfo[] consList = modelMBeanConstructors;
        int numCons = 0;
        if (consList != null)
            numCons = consList.length;
        final MBeanNotificationInfo[] notifList = modelMBeanNotifications;
        int numNotifs = 0;
        if (notifList != null)
            numNotifs = notifList.length;
        int count = numAttrs + numCons + numOpers + numNotifs + 1;
        retList = new Descriptor[count];
        retList[count - 1] = modelMBeanDescriptor;
        int j = 0;
        for (int i = 0; i < numAttrs; i++) {
            retList[j] = (((ModelMBeanAttributeInfo) attrList[i]).getDescriptor());
            j++;
        }
        for (int i = 0; i < numCons; i++) {
            retList[j] = (((ModelMBeanConstructorInfo) consList[i]).getDescriptor());
            j++;
        }
        for (int i = 0; i < numOpers; i++) {
            retList[j] = (((ModelMBeanOperationInfo) operList[i]).getDescriptor());
            j++;
        }
        for (int i = 0; i < numNotifs; i++) {
            retList[j] = (((ModelMBeanNotificationInfo) notifList[i]).getDescriptor());
            j++;
        }
    } else {
        final IllegalArgumentException iae = new IllegalArgumentException("Descriptor Type is invalid");
        final String msg = "Exception occurred trying to find" + " the descriptors of the MBean";
        throw new RuntimeOperationsException(iae, msg);
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, ModelMBeanInfoSupport.class.getName(), "getDescriptors(String)", "Exit");
    }
    return retList;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) Descriptor(javax.management.Descriptor) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

MBeanOperationInfo (javax.management.MBeanOperationInfo)46 MBeanInfo (javax.management.MBeanInfo)33 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)24 ObjectName (javax.management.ObjectName)18 MBeanParameterInfo (javax.management.MBeanParameterInfo)17 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 MBeanServer (javax.management.MBeanServer)8 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)7 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)7 ReflectionException (javax.management.ReflectionException)5 Method (java.lang.reflect.Method)4 Descriptor (javax.management.Descriptor)4 TreeMap (java.util.TreeMap)3 Attribute (javax.management.Attribute)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 IntrospectionException (javax.management.IntrospectionException)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 OpenType (javax.management.openmbean.OpenType)3 IOException (java.io.IOException)2