Search in sources :

Example 76 with ObjectInstance

use of javax.management.ObjectInstance in project cxf by apache.

the class ManagedRMManagerTest method testManagedRMManager.

@Test
public void testManagedRMManager() throws Exception {
    final SpringBusFactory factory = new SpringBusFactory();
    bus = factory.createBus("org/apache/cxf/ws/rm/managed-manager-bean.xml");
    im = bus.getExtension(InstrumentationManager.class);
    manager = bus.getExtension(RMManager.class);
    endpoint = createTestEndpoint();
    assertNotNull("Instrumentation Manager should not be null", im);
    assertNotNull("RMManager should not be null", manager);
    MBeanServer mbs = im.getMBeanServer();
    assertNotNull("MBeanServer should be available.", mbs);
    ObjectName managerName = RMUtils.getManagedObjectName(manager);
    Set<ObjectInstance> mbset = mbs.queryMBeans(managerName, null);
    assertEquals("ManagedRMManager should be found", 1, mbset.size());
    Object o;
    o = mbs.getAttribute(managerName, "UsingStore");
    assertTrue(o instanceof Boolean);
    assertFalse("Store attribute is false", (Boolean) o);
    o = mbs.invoke(managerName, "getEndpointIdentifiers", null, null);
    assertTrue(o instanceof String[]);
    assertEquals("No Endpoint", 0, ((String[]) o).length);
    RMEndpoint rme = createTestRMEndpoint();
    ObjectName endpointName = RMUtils.getManagedObjectName(rme);
    mbset = mbs.queryMBeans(endpointName, null);
    assertEquals("ManagedRMEndpoint should be found", 1, mbset.size());
    o = mbs.invoke(managerName, "getEndpointIdentifiers", null, null);
    assertEquals("One Endpoint", 1, ((String[]) o).length);
    assertEquals("Endpoint identifier must match", RMUtils.getEndpointIdentifier(endpoint, bus), ((String[]) o)[0]);
    // test some endpoint methods
    o = mbs.getAttribute(endpointName, "Address");
    assertTrue(o instanceof String);
    assertEquals("Endpoint address must match", TEST_URI, o);
    o = mbs.getAttribute(endpointName, "LastApplicationMessage");
    assertNull(o);
    o = mbs.getAttribute(endpointName, "LastControlMessage");
    assertNull(o);
    o = mbs.invoke(endpointName, "getDestinationSequenceIds", null, null);
    assertTrue(o instanceof String[]);
    assertEquals("No sequence", 0, ((String[]) o).length);
    o = mbs.invoke(endpointName, "getDestinationSequences", null, null);
    assertTrue(o instanceof CompositeData[]);
    assertEquals("No sequence", 0, ((CompositeData[]) o).length);
    o = mbs.invoke(endpointName, "getSourceSequenceIds", new Object[] { true }, new String[] { "boolean" });
    assertTrue(o instanceof String[]);
    assertEquals("No sequence", 0, ((String[]) o).length);
    o = mbs.invoke(endpointName, "getSourceSequences", new Object[] { true }, new String[] { "boolean" });
    assertTrue(o instanceof CompositeData[]);
    assertEquals("No sequence", 0, ((CompositeData[]) o).length);
    o = mbs.invoke(endpointName, "getDeferredAcknowledgementTotalCount", null, null);
    assertTrue(o instanceof Integer);
    assertEquals("No deferred acks", 0, o);
    o = mbs.invoke(endpointName, "getQueuedMessageTotalCount", new Object[] { true }, new String[] { "boolean" });
    assertTrue(o instanceof Integer);
    assertEquals("No queued messages", 0, o);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ObjectInstance(javax.management.ObjectInstance) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) ObjectName(javax.management.ObjectName) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 77 with ObjectInstance

use of javax.management.ObjectInstance in project karaf by apache.

the class EventAdminMBeanServerWrapper method getObjectInstance.

@Override
public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException {
    Throwable error = null;
    ObjectInstance result = null;
    try {
        return result = delegate.getObjectInstance(name);
    } catch (Throwable e) {
        error = e;
        throw e;
    } finally {
        log(GET_OBJECT_INSTANCE, GET_OBJECT_INSTANCE_SIG, result, error, name);
    }
}
Also used : ObjectInstance(javax.management.ObjectInstance)

Example 78 with ObjectInstance

use of javax.management.ObjectInstance in project neo4j-documentation by neo4j.

the class JmxBeanDocumenter method asDetails.

private void asDetails(ObjectName objectName, String name, PrintStream out) throws IntrospectionException, InstanceNotFoundException, ReflectionException {
    Set<ObjectInstance> mBeans = mBeanServer.queryMBeans(objectName, null);
    if (mBeans.size() != 1) {
        throw new IllegalStateException(String.format("Unexpected size [%s] of query result for [%s].", mBeans.size(), objectName));
    }
    ObjectInstance bean = mBeans.iterator().next();
    MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
    String description = info.getDescription().replace('\n', ' ');
    String id = getId(name);
    String name0 = objectName.getKeyProperty("name0");
    if (name0 != null) {
        name += "/" + name0;
    }
    List<MBeanAttributeInfo> attributes = Arrays.asList(info.getAttributes());
    if (name.equalsIgnoreCase("Configuration")) {
        attributes = attributes.stream().filter(it -> !it.getName().startsWith("unsupported")).collect(Collectors.toList());
    }
    out.printf("[[%s]]%n", id);
    if (attributes.size() > 0) {
        out.printf(".MBean %s (%s) Attributes%n", name, bean.getClassName());
        attributesTable(description, out, attributes, false);
        attributesTable(description, out, attributes, true);
        out.println();
    }
    List<MBeanOperationInfo> operations = Arrays.asList(info.getOperations());
    if (operations.size() > 0) {
        out.printf(".MBean %s (%s) Operations%n", name, bean.getClassName());
        operationsTable(out, operations, false);
        operationsTable(out, operations, true);
        out.println();
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) ObjectInstance(javax.management.ObjectInstance) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 79 with ObjectInstance

use of javax.management.ObjectInstance in project jersey by jersey.

the class MBeansTest method checkResourceMBean.

private void checkResourceMBean(String name) throws MalformedObjectNameException {
    final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    final ObjectName objectName = new ObjectName("org.glassfish.jersey:type=myApplication,subType=Uris,resource=\"" + name + "\"");
    ObjectInstance mbean = null;
    try {
        mbean = mBeanServer.getObjectInstance(objectName);
    } catch (InstanceNotFoundException e) {
        Assert.fail("Resource MBean name '" + name + "' not found.");
    }
    assertNotNull(mbean);
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 80 with ObjectInstance

use of javax.management.ObjectInstance in project metrics by dropwizard.

the class JmxAttributeGaugeTest method registerMBean.

private static void registerMBean(ObjectName objectName) throws JMException {
    ObjectInstance objectInstance = mBeanServer.registerMBean(new JmxTest(), objectName);
    registeredMBeans.add(objectInstance.getObjectName());
}
Also used : ObjectInstance(javax.management.ObjectInstance)

Aggregations

ObjectInstance (javax.management.ObjectInstance)172 ObjectName (javax.management.ObjectName)102 Test (org.junit.Test)38 MBeanServer (javax.management.MBeanServer)36 InstanceNotFoundException (javax.management.InstanceNotFoundException)28 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)16 MBeanInfo (javax.management.MBeanInfo)16 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)15 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)15 HashMap (java.util.HashMap)13 Attribute (javax.management.Attribute)13 HashSet (java.util.HashSet)12 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)11 Result (com.googlecode.jmxtrans.model.Result)11 Set (java.util.Set)11 ReflectionException (javax.management.ReflectionException)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 Test (org.junit.jupiter.api.Test)10 MBeanServerConnection (javax.management.MBeanServerConnection)9