Search in sources :

Example 6 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);
        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 7 with InstrumentationManagerImpl

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

the class CxfUtil method configureBus.

public static void configureBus() {
    if (USER_COUNT.incrementAndGet() > 1) {
        return;
    }
    final SystemInstance systemInstance = SystemInstance.get();
    final Bus bus = getBus();
    // ensure cxf classes are loaded from container to avoid conflicts with app
    if ("true".equalsIgnoreCase(systemInstance.getProperty("openejb.cxf.CxfContainerClassLoader", "true"))) {
        bus.setExtension(new CxfContainerClassLoader(), ClassLoader.class);
    }
    // activate jmx, by default isEnabled() == false in InstrumentationManagerImpl
    final boolean hasMonitoring = hasMonitoring(systemInstance);
    if (hasMonitoring || "true".equalsIgnoreCase(systemInstance.getProperty("openejb.cxf.jmx", "true"))) {
        final InstrumentationManager mgr = bus.getExtension(InstrumentationManager.class);
        if (InstrumentationManagerImpl.class.isInstance(mgr)) {
            // just to keep everything consistent
            bus.setExtension(LocalMBeanServer.get(), MBeanServer.class);
            final InstrumentationManagerImpl manager = InstrumentationManagerImpl.class.cast(mgr);
            manager.setEnabled(true);
            manager.setServer(LocalMBeanServer.get());
            try {
                // avoid to bother our nice logs
                LogUtils.getL7dLogger(InstrumentationManagerImpl.class).setLevel(Level.WARNING);
            } catch (final Throwable th) {
            // no-op
            }
            // failed when bus was constructed or even if passed we switch the MBeanServer
            manager.init();
        }
    }
    if (hasMonitoring) {
        new CounterRepository().setBus(bus);
    }
    final ServiceConfiguration configuration = new ServiceConfiguration(systemInstance.getProperties(), systemInstance.getComponent(OpenEjbConfiguration.class).facilities.services);
    final Collection<ServiceInfo> serviceInfos = configuration.getAvailableServices();
    Properties properties = configuration.getProperties();
    if (properties == null) {
        properties = new Properties();
    }
    final String featuresIds = properties.getProperty(BUS_PREFIX + FEATURES);
    if (featuresIds != null) {
        final List<Feature> features = createFeatures(serviceInfos, featuresIds);
        if (features != null) {
            features.addAll(bus.getFeatures());
            bus.setFeatures(features);
        }
    }
    final Properties busProperties = ServiceInfos.serviceProperties(serviceInfos, properties.getProperty(BUS_PREFIX + ENDPOINT_PROPERTIES));
    if (busProperties != null) {
        bus.getProperties().putAll(PropertiesHelper.map(busProperties));
    }
    configureInterceptors(bus, BUS_PREFIX, serviceInfos, configuration.getProperties());
    systemInstance.getProperties().setProperty(BUS_CONFIGURED_FLAG, "true");
    systemInstance.fireEvent(new BusCreated(bus));
}
Also used : Bus(org.apache.cxf.Bus) CounterRepository(org.apache.cxf.management.counters.CounterRepository) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) Properties(java.util.Properties) BusCreated(org.apache.openejb.server.cxf.transport.event.BusCreated) Feature(org.apache.cxf.feature.Feature) AbstractFeature(org.apache.cxf.feature.AbstractFeature) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) ServiceInfo(org.apache.openejb.assembler.classic.ServiceInfo) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) SystemInstance(org.apache.openejb.loader.SystemInstance)

Example 8 with InstrumentationManagerImpl

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

the class CountersClientServerTest method testCountersWithInstrumentationManager.

@Test
public void testCountersWithInstrumentationManager() throws Exception {
    // create Client with other bus
    Bus bus = getStaticBus();
    BusFactory.setDefaultBus(bus);
    bus.getExtension(WorkQueueManager.class);
    CounterRepository cr = bus.getExtension(CounterRepository.class);
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    assertNotNull(im);
    InstrumentationManagerImpl impl = (InstrumentationManagerImpl) im;
    assertTrue(impl.isEnabled());
    assertNotNull(impl.getMBeanServer());
    MBeanServer mbs = im.getMBeanServer();
    ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":" + ManagementConstants.BUS_ID_PROP + "=cxf" + bus.hashCode() + ",*");
    SOAPService service = new SOAPService();
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    String response = new String("Bonjour");
    String reply = greeter.sayHi();
    // assertNotNull("no response received from service", reply);
    // assertEquals(response, reply);
    assertEquals("The Counters are not create yet", 4, cr.getCounters().size());
    Set<?> counterNames = mbs.queryNames(name, null);
    assertEquals("The Counters are not export to JMX: " + counterNames, 4 + 3, counterNames.size());
    ObjectName sayHiCounter = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":operation=\"sayHi\",*");
    Set<?> s = mbs.queryNames(sayHiCounter, null);
    Iterator<?> it = s.iterator();
    while (it.hasNext()) {
        ObjectName counterName = (ObjectName) it.next();
        Object val = mbs.getAttribute(counterName, "NumInvocations");
        assertEquals("Wrong Counters Number of Invocations", val, 1);
    }
    reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals(response, reply);
    s = mbs.queryNames(sayHiCounter, null);
    it = s.iterator();
    while (it.hasNext()) {
        ObjectName counterName = (ObjectName) it.next();
        Object val = mbs.getAttribute(counterName, "NumInvocations");
        assertEquals("Wrong Counters Number of Invocations", val, 2);
    }
    greeter.greetMeOneWay("hello");
    for (int count = 0; count < 10; count++) {
        if (6 != cr.getCounters().size()) {
            Thread.sleep(100);
        } else {
            break;
        }
    }
    assertEquals("The Counters are not create yet", 6, cr.getCounters().size());
    for (int count = 0; count < 10; count++) {
        if (10 > mbs.queryNames(name, null).size()) {
            Thread.sleep(100);
        } else {
            break;
        }
    }
    counterNames = mbs.queryNames(name, null);
    assertEquals("The Counters are not export to JMX " + counterNames, 6 + 4, counterNames.size());
    ObjectName greetMeOneWayCounter = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":operation=\"greetMeOneWay\",*");
    s = mbs.queryNames(greetMeOneWayCounter, null);
    it = s.iterator();
    while (it.hasNext()) {
        ObjectName counterName = (ObjectName) it.next();
        Object val = mbs.getAttribute(counterName, "NumInvocations");
        assertEquals("Wrong Counters Number of Invocations", val, 1);
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Bus(org.apache.cxf.Bus) CounterRepository(org.apache.cxf.management.counters.CounterRepository) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) Endpoint(javax.xml.ws.Endpoint) ObjectName(javax.management.ObjectName) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Greeter(org.apache.hello_world_soap_http.Greeter) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 9 with InstrumentationManagerImpl

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

the class ManagedClientServerTest method testManagedEndpoint.

@Test
public void testManagedEndpoint() throws Exception {
    Bus bus = getStaticBus();
    BusFactory.setDefaultBus(bus);
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    assertNotNull(im);
    InstrumentationManagerImpl impl = (InstrumentationManagerImpl) im;
    assertTrue(impl.isEnabled());
    assertNotNull(impl.getMBeanServer());
    MBeanServer mbs = im.getMBeanServer();
    ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=Bus.Service.Endpoint,*");
    Set<?> s = mbs.queryNames(name, null);
    assertEquals(1, s.size());
    name = (ObjectName) s.iterator().next();
    Object val = mbs.invoke(name, "getState", new Object[0], new String[0]);
    assertEquals("Service should have been started.", "STARTED", val);
    SOAPService service = new SOAPService();
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    String response = new String("Bonjour");
    String reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals(response, reply);
    mbs.invoke(name, "stop", new Object[0], new String[0]);
    val = mbs.getAttribute(name, "State");
    assertEquals("Service should have been stopped.", "STOPPED", val);
    try {
        reply = greeter.sayHi();
        fail("Endpoint should not be active at this point.");
    } catch (Exception ex) {
    // Expected
    }
    mbs.invoke(name, "start", new Object[0], new String[0]);
    val = mbs.invoke(name, "getState", new Object[0], new String[0]);
    assertEquals("Service should have been started.", "STARTED", val);
    reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals(response, reply);
    mbs.invoke(name, "destroy", new Object[0], new String[0]);
    try {
        mbs.getMBeanInfo(name);
        fail("destroy failed to unregister MBean.");
    } catch (InstanceNotFoundException e) {
    // Expected
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Bus(org.apache.cxf.Bus) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Greeter(org.apache.hello_world_soap_http.Greeter) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 10 with InstrumentationManagerImpl

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

the class ManagedBusTest method testManagedSpringBus.

@Test
public void testManagedSpringBus() throws Exception {
    SpringBusFactory factory = new SpringBusFactory();
    Bus bus = factory.createBus();
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    assertNotNull(im);
    InstrumentationManagerImpl imi = (InstrumentationManagerImpl) im;
    assertFalse(imi.isEnabled());
    assertNull(imi.getMBeanServer());
    // Test that registering without an MBeanServer is a no-op
    im.register(imi, new ObjectName("org.apache.cxf:foo=bar"));
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

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 ManagedEndpoint (org.apache.cxf.endpoint.ManagedEndpoint)4 Greeter (org.apache.hello_world_soap_http.Greeter)3 ArrayList (java.util.ArrayList)2 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)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