Search in sources :

Example 1 with InstrumentationManagerImpl

use of org.apache.cxf.management.jmx.InstrumentationManagerImpl in project fabric8 by jboss-fuse.

the class EnableJMXFeature method initialize.

@Override
public void initialize(Bus bus) {
    List<Server> servers = new ArrayList<Server>();
    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    servers.addAll(serverRegistry.getServers());
    for (Iterator<Server> iter = servers.iterator(); iter.hasNext(); ) {
        Server server = (Server) iter.next();
        ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
        InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
        if (iMgr == null) {
            iMgr = new InstrumentationManagerImpl(bus);
        }
        ((InstrumentationManagerImpl) iMgr).setUsePlatformMBeanServer(true);
        ((InstrumentationManagerImpl) iMgr).setCreateMBServerConnectorFactory(false);
        ((InstrumentationManagerImpl) iMgr).setEnabled(true);
        ((InstrumentationManagerImpl) iMgr).init();
        if (iMgr != null) {
            try {
                iMgr.register(mApi);
            } catch (JMException jmex) {
                jmex.printStackTrace();
                LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
            }
        }
    }
}
Also used : InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Server(org.apache.cxf.endpoint.Server) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 2 with InstrumentationManagerImpl

use of org.apache.cxf.management.jmx.InstrumentationManagerImpl in project fabric8 by fabric8io.

the class EnableJMXFeature method initialize.

@Override
public void initialize(Bus bus) {
    List<Server> servers = new ArrayList<Server>();
    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    servers.addAll(serverRegistry.getServers());
    for (Iterator<Server> iter = servers.iterator(); iter.hasNext(); ) {
        Server server = (Server) iter.next();
        ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
        ManagedEndpoint mEndpoint = new ManagedEndpoint(bus, server.getEndpoint(), server);
        InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
        if (iMgr == null) {
            iMgr = new InstrumentationManagerImpl(bus);
        }
        ((InstrumentationManagerImpl) iMgr).setUsePlatformMBeanServer(true);
        ((InstrumentationManagerImpl) iMgr).setCreateMBServerConnectorFactory(false);
        ((InstrumentationManagerImpl) iMgr).setEnabled(true);
        ((InstrumentationManagerImpl) iMgr).init();
        if (iMgr != null) {
            try {
                iMgr.register(mApi);
                iMgr.register(mEndpoint);
            } catch (JMException jmex) {
                jmex.printStackTrace();
                LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
            }
        }
    }
}
Also used : InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Server(org.apache.cxf.endpoint.Server) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) ManagedEndpoint(org.apache.cxf.endpoint.ManagedEndpoint) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 3 with InstrumentationManagerImpl

use of org.apache.cxf.management.jmx.InstrumentationManagerImpl in project fabric8 by fabric8io.

the class EnableJMXFeature method initialize.

@Override
public void initialize(Server server, Bus bus) {
    ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
    ManagedEndpoint mEndpoint = new ManagedEndpoint(bus, server.getEndpoint(), server);
    InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
    if (iMgr == null) {
        iMgr = new InstrumentationManagerImpl(bus);
    }
    ((InstrumentationManagerImpl) iMgr).setUsePlatformMBeanServer(true);
    ((InstrumentationManagerImpl) iMgr).setCreateMBServerConnectorFactory(false);
    ((InstrumentationManagerImpl) iMgr).setEnabled(true);
    ((InstrumentationManagerImpl) iMgr).init();
    if (iMgr != null) {
        try {
            iMgr.register(mApi);
            iMgr.register(mEndpoint);
            ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class);
            if (slcMgr != null) {
                slcMgr.registerListener(mApi);
                slcMgr.registerListener(mEndpoint);
                mApi.startServer(server);
                mEndpoint.startServer(server);
            }
        } catch (JMException jmex) {
            jmex.printStackTrace();
            LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
        }
    }
}
Also used : InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) JMException(javax.management.JMException) ManagedEndpoint(org.apache.cxf.endpoint.ManagedEndpoint) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 4 with InstrumentationManagerImpl

use of org.apache.cxf.management.jmx.InstrumentationManagerImpl in project cxf by apache.

the class InstrumentationManagerTest method testInstrumentBusWithBusProperties.

@Test
public void testInstrumentBusWithBusProperties() {
    Bus cxf1 = null;
    Bus cxf2 = null;
    try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("managed-spring-twobuses2.xml")) {
        cxf1 = (Bus) context.getBean("cxf1");
        InstrumentationManagerImpl im1 = (InstrumentationManagerImpl) cxf1.getExtension(InstrumentationManager.class);
        assertNotNull("Instrumentation Manager of cxf1 should not be null", im1);
        assertTrue(im1.isEnabled());
        cxf2 = (Bus) context.getBean("cxf2");
        InstrumentationManagerImpl im2 = (InstrumentationManagerImpl) cxf2.getExtension(InstrumentationManager.class);
        assertNotNull("Instrumentation Manager of cxf2 should not be null", im2);
        assertFalse(im2.isEnabled());
    } finally {
        if (cxf1 != null) {
            cxf1.shutdown(true);
        }
        if (cxf2 != null) {
            cxf2.shutdown(true);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 5 with InstrumentationManagerImpl

use of org.apache.cxf.management.jmx.InstrumentationManagerImpl in project cxf by apache.

the class ManagedBusTest method doManagedBusTest.

private void doManagedBusTest(Bus bus, String expect, String reject, int port) throws Exception {
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    assertNotNull(im);
    InstrumentationManagerImpl imi = (InstrumentationManagerImpl) im;
    assertTrue(imi.isEnabled());
    assertNotNull(imi.getMBeanServer());
    WorkQueueManager manager = bus.getExtension(WorkQueueManager.class);
    MBeanServer mbs = im.getMBeanServer();
    ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=WorkQueueManager,*");
    Set<?> s = mbs.queryNames(name, null);
    StringBuilder b = new StringBuilder();
    for (ObjectName o : CastUtils.cast(s, ObjectName.class)) {
        b.append(o.toString());
        assertTrue("expected " + expect + " in object name: " + o, o.toString().indexOf("bus.id=" + expect + ",") != -1);
        assertTrue("unexpected " + reject + " in object name: " + o, o.toString().indexOf("bus.id=" + reject + ",") == -1);
        b.append('\n');
    }
    assertEquals("Size is wrong: " + b.toString(), 1, s.size());
    assertNotNull(manager.getNamedWorkQueue("testQueue"));
    manager.getAutomaticWorkQueue();
    name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=WorkQueues,*");
    s = mbs.queryNames(name, null);
    b = new StringBuilder();
    for (ObjectName o : CastUtils.cast(s, ObjectName.class)) {
        b.append(o.toString());
        assertTrue("expected " + expect + " in object name: " + o, o.toString().indexOf("bus.id=" + expect + ",") != -1);
        assertTrue("unexpected " + reject + " in object name: " + o, o.toString().indexOf("bus.id=" + reject + ",") == -1);
        b.append('\n');
    }
    assertEquals("Size is wrong: " + b.toString(), 2, s.size());
    Iterator<?> it = s.iterator();
    while (it.hasNext()) {
        ObjectName n = (ObjectName) it.next();
        Long result = (Long) mbs.invoke(n, "getWorkQueueMaxSize", new Object[0], new String[0]);
        assertEquals(result, Long.valueOf(256));
        Integer hwm = (Integer) mbs.invoke(n, "getHighWaterMark", new Object[0], new String[0]);
        if (n.toString().contains("testQueue")) {
            assertEquals(hwm, Integer.valueOf(50));
        } else {
            assertEquals(hwm, Integer.valueOf(25));
        }
    }
    name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=Bus,*");
    s = mbs.queryNames(name, null);
    assertTrue(s.size() == 1);
    it = s.iterator();
    while (it.hasNext()) {
        ObjectName n = (ObjectName) it.next();
        Object[] params = { Boolean.FALSE };
        String[] sig = { "boolean" };
        mbs.invoke(n, "shutdown", params, sig);
    }
    bus.shutdown(true);
}
Also used : InstrumentationManager(org.apache.cxf.management.InstrumentationManager) ObjectName(javax.management.ObjectName) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) MBeanServer(javax.management.MBeanServer)

Aggregations

InstrumentationManagerImpl (org.apache.cxf.management.jmx.InstrumentationManagerImpl)11 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)10 Bus (org.apache.cxf.Bus)6 ObjectName (javax.management.ObjectName)5 Test (org.junit.Test)5 JMException (javax.management.JMException)4 MBeanServer (javax.management.MBeanServer)4 Greeter (org.apache.hello_world_soap_http.Greeter)3 ArrayList (java.util.ArrayList)2 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)2 ManagedEndpoint (org.apache.cxf.endpoint.ManagedEndpoint)2 Server (org.apache.cxf.endpoint.Server)2 ServerLifeCycleManager (org.apache.cxf.endpoint.ServerLifeCycleManager)2 ServerRegistry (org.apache.cxf.endpoint.ServerRegistry)2 CounterRepository (org.apache.cxf.management.counters.CounterRepository)2 SOAPService (org.apache.hello_world_soap_http.SOAPService)2 Properties (java.util.Properties)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 Endpoint (javax.xml.ws.Endpoint)1 AbstractFeature (org.apache.cxf.feature.AbstractFeature)1