Search in sources :

Example 51 with ObjectInstance

use of javax.management.ObjectInstance in project spring-framework by spring-projects.

the class MBeanExporterTests method testRegisterReplaceExisting.

@Test
public void testRegisterReplaceExisting() throws Exception {
    ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);
    Person preRegistered = new Person();
    preRegistered.setName("Rob Harrop");
    server.registerMBean(preRegistered, objectName);
    Person springRegistered = new Person();
    springRegistered.setName("Sally Greenwood");
    Map<String, Object> beans = new HashMap<>();
    beans.put(objectName.toString(), springRegistered);
    MBeanExporter exporter = new MBeanExporter();
    exporter.setServer(server);
    exporter.setBeans(beans);
    exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);
    start(exporter);
    ObjectInstance instance = server.getObjectInstance(objectName);
    assertNotNull(instance);
    // should still be the new bean with name Sally Greenwood
    assertEquals("Sally Greenwood", server.getAttribute(objectName, "Name"));
}
Also used : HashMap(java.util.HashMap) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 52 with ObjectInstance

use of javax.management.ObjectInstance in project spring-framework by spring-projects.

the class MBeanExporterTests method testAutodetectWithExclude.

@Test
public void testAutodetectWithExclude() throws Exception {
    ConfigurableApplicationContext ctx = load("autodetectMBeans.xml");
    try {
        ctx.getBean("exporter");
        MBeanServer server = ctx.getBean("server", MBeanServer.class);
        ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true"));
        assertNotNull(instance);
        thrown.expect(InstanceNotFoundException.class);
        server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false"));
    } finally {
        ctx.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ObjectInstance(javax.management.ObjectInstance) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 53 with ObjectInstance

use of javax.management.ObjectInstance in project spring-framework by spring-projects.

the class AbstractJmxAssemblerTests method testMBeanRegistration.

@Test
public void testMBeanRegistration() throws Exception {
    // beans are registered at this point - just grab them from the server
    ObjectInstance instance = getObjectInstance();
    assertNotNull("Bean should not be null", instance);
}
Also used : ObjectInstance(javax.management.ObjectInstance) Test(org.junit.Test)

Example 54 with ObjectInstance

use of javax.management.ObjectInstance in project opennms by OpenNMS.

the class Invoker method invokeMethods.

/**
     * <p>invokeMethods</p>
     *
     * @return a {@link java.util.List} object.
     */
public List<InvokerResult> invokeMethods() {
    List<InvokerService> invokerServicesOrdered;
    if (isReverse()) {
        invokerServicesOrdered = new ArrayList<InvokerService>(getServices());
        Collections.reverse(invokerServicesOrdered);
    } else {
        // We can  use the original list
        invokerServicesOrdered = getServices();
    }
    List<InvokerResult> resultInfo = new ArrayList<InvokerResult>(invokerServicesOrdered.size());
    for (int pass = 0, end = getLastPass(); pass <= end; pass++) {
        LOG.debug("starting pass {}", pass);
        for (InvokerService invokerService : invokerServicesOrdered) {
            Service service = invokerService.getService();
            String name = invokerService.getService().getName();
            ObjectInstance mbean = invokerService.getMbean();
            if (invokerService.isBadService()) {
                resultInfo.add(new InvokerResult(service, mbean, null, invokerService.getBadThrowable()));
                if (isFailFast()) {
                    return resultInfo;
                }
            }
            for (final Invoke invoke : invokerService.getService().getInvokes()) {
                if (invoke.getPass() != pass || !getAtType().equals(invoke.getAt())) {
                    continue;
                }
                LOG.debug("pass {} on service {} will invoke method \"{}\"", pass, name, invoke.getMethod());
                try {
                    Object result = invoke(invoke, mbean);
                    resultInfo.add(new InvokerResult(service, mbean, result, null));
                } catch (Throwable t) {
                    resultInfo.add(new InvokerResult(service, mbean, null, t));
                    if (isFailFast()) {
                        return resultInfo;
                    }
                }
            }
        }
        LOG.debug("completed pass {}", pass);
    }
    return resultInfo;
}
Also used : ArrayList(java.util.ArrayList) ObjectInstance(javax.management.ObjectInstance) Service(org.opennms.netmgt.config.service.Service) Invoke(org.opennms.netmgt.config.service.Invoke)

Example 55 with ObjectInstance

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

the class LogStoreProbeHandler method addTransactions.

private void addTransactions(final Resource parent, Set<ObjectInstance> transactions, MBeanServer mbs) throws IntrospectionException, InstanceNotFoundException, IOException, ReflectionException, MalformedObjectNameException {
    for (ObjectInstance oi : transactions) {
        String transactionId = oi.getObjectName().getCanonicalName();
        if (!transactionId.contains("puid") && transactionId.contains("itype")) {
            final Resource transaction = new LogStoreResource.LogStoreRuntimeResource(oi.getObjectName());
            final ModelNode model = transaction.getModel();
            Map<String, String> tAttributes = getMBeanValues(mbs, oi.getObjectName(), LogStoreConstants.TXN_JMX_NAMES);
            String txnId = tAttributes.get("Id");
            addAttributes(model, LogStoreConstants.MODEL_TO_JMX_TXN_NAMES, tAttributes);
            // model.get(LogStoreConstants.JMX_ON_ATTRIBUTE).set(transactionId);
            String participantQuery = transactionId + ",puid=*";
            Set<ObjectInstance> participants = mbs.queryMBeans(new ObjectName(participantQuery), null);
            addParticipants(transaction, participants, mbs);
            final PathElement element = PathElement.pathElement(LogStoreConstants.TRANSACTIONS, txnId);
            parent.registerChild(element, transaction);
        }
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) ObjectInstance(javax.management.ObjectInstance) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) ObjectName(javax.management.ObjectName)

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