Search in sources :

Example 1 with CounterRepository

use of org.apache.cxf.management.counters.CounterRepository in project cxf by apache.

the class InstrumentationManagerTest method testInstrumentTwoBuses.

@Test
public void testInstrumentTwoBuses() {
    ClassPathXmlApplicationContext context = null;
    Bus cxf1 = null;
    Bus cxf2 = null;
    try {
        context = new ClassPathXmlApplicationContext("managed-spring-twobuses.xml");
        cxf1 = (Bus) context.getBean("cxf1");
        InstrumentationManager im1 = cxf1.getExtension(InstrumentationManager.class);
        assertNotNull("Instrumentation Manager of cxf1 should not be null", im1);
        CounterRepository cr1 = cxf1.getExtension(CounterRepository.class);
        assertNotNull("CounterRepository of cxf1 should not be null", cr1);
        assertEquals("CounterRepository of cxf1 has the wrong bus", cxf1, cr1.getBus());
        cxf2 = (Bus) context.getBean("cxf2");
        InstrumentationManager im2 = cxf2.getExtension(InstrumentationManager.class);
        assertNotNull("Instrumentation Manager of cxf2 should not be null", im2);
        CounterRepository cr2 = cxf2.getExtension(CounterRepository.class);
        assertNotNull("CounterRepository of cxf2 should not be null", cr2);
        assertEquals("CounterRepository of cxf2 has the wrong bus", cxf2, cr2.getBus());
    } finally {
        if (cxf1 != null) {
            cxf1.shutdown(true);
        }
        if (cxf2 != null) {
            cxf2.shutdown(true);
        }
        if (context != null) {
            context.close();
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) CounterRepository(org.apache.cxf.management.counters.CounterRepository) Test(org.junit.Test)

Example 2 with CounterRepository

use of org.apache.cxf.management.counters.CounterRepository 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 3 with CounterRepository

use of org.apache.cxf.management.counters.CounterRepository in project cxf by apache.

the class AbstractMessageResponseTimeInterceptor method isServiceCounterEnabled.

protected boolean isServiceCounterEnabled(Exchange ex) {
    Bus bus = ex.getBus();
    CounterRepository counterRepo = bus.getExtension(CounterRepository.class);
    if (counterRepo == null) {
        return false;
    }
    ObjectName serviceCounterName = getServiceCounterName(ex);
    Counter serviceCounter = counterRepo.getCounter(serviceCounterName);
    // If serviceCounter is null, we need to wait ResponseTimeOutInterceptor to create it , hence set to true
    return serviceCounter == null || serviceCounter.isEnabled();
}
Also used : Bus(org.apache.cxf.Bus) Counter(org.apache.cxf.management.counters.Counter) CounterRepository(org.apache.cxf.management.counters.CounterRepository) ObjectName(javax.management.ObjectName)

Example 4 with CounterRepository

use of org.apache.cxf.management.counters.CounterRepository in project cxf by apache.

the class AbstractMessageResponseTimeInterceptor method increaseCounter.

private void increaseCounter(Exchange ex, MessageHandlingTimeRecorder mhtr) {
    Bus bus = ex.getBus();
    if (null == bus) {
        LOG.log(Level.INFO, "CAN_NOT_GET_BUS_FROM_EXCHANGE");
        bus = BusFactory.getThreadDefaultBus();
    }
    CounterRepository cr = bus.getExtension(CounterRepository.class);
    if (null == cr) {
        LOG.log(Level.WARNING, "NO_COUNTER_REPOSITORY");
        return;
    }
    ObjectName serviceCountername = this.getServiceCounterName(ex);
    cr.increaseCounter(serviceCountername, mhtr);
    ObjectName operationCounter = this.getOperationCounterName(ex, serviceCountername);
    cr.increaseCounter(operationCounter, mhtr);
}
Also used : Bus(org.apache.cxf.Bus) CounterRepository(org.apache.cxf.management.counters.CounterRepository) ObjectName(javax.management.ObjectName)

Example 5 with CounterRepository

use of org.apache.cxf.management.counters.CounterRepository in project jbossws-cxf by jbossws.

the class BusHolder method setCXFManagement.

protected static void setCXFManagement(Bus bus, Map<String, String> props) {
    if (props != null && !props.isEmpty()) {
        final String p = props.get(Constants.CXF_MANAGEMENT_ENABLED);
        if ("true".equalsIgnoreCase(p) || "1".equalsIgnoreCase(p)) {
            InstrumentationManagerExtImpl instrumentationManagerImpl = new InstrumentationManagerExtImpl();
            instrumentationManagerImpl.setBus(bus);
            instrumentationManagerImpl.setEnabled(true);
            instrumentationManagerImpl.init();
            instrumentationManagerImpl.initMBeanServer();
            bus.setExtension(instrumentationManagerImpl, InstrumentationManager.class);
            CounterRepository couterRepository = new CounterRepository();
            couterRepository.setBus(bus);
            final String installRespTimeInterceptors = props.get(Constants.CXF_MANAGEMENT_INSTALL_RESPONSE_TIME_INTERCEPTORS);
            if (installRespTimeInterceptors == null || "true".equalsIgnoreCase(installRespTimeInterceptors) || "1".equalsIgnoreCase(installRespTimeInterceptors)) {
                ResponseTimeMessageInInterceptor in = new ResponseTimeMessageInInterceptor();
                ResponseTimeMessageInvokerInterceptor invoker = new ResponseTimeMessageInvokerInterceptor();
                ResponseTimeMessageOutInterceptor out = new ResponseTimeMessageOutInterceptor();
                bus.getInInterceptors().add(in);
                bus.getInInterceptors().add(invoker);
                bus.getOutInterceptors().add(out);
            }
            bus.setExtension(couterRepository, CounterRepository.class);
        }
    }
}
Also used : ResponseTimeMessageOutInterceptor(org.apache.cxf.management.interceptor.ResponseTimeMessageOutInterceptor) InstrumentationManagerExtImpl(org.jboss.wsf.stack.cxf.management.InstrumentationManagerExtImpl) ResponseTimeMessageInInterceptor(org.apache.cxf.management.interceptor.ResponseTimeMessageInInterceptor) CounterRepository(org.apache.cxf.management.counters.CounterRepository) ResponseTimeMessageInvokerInterceptor(org.apache.cxf.management.interceptor.ResponseTimeMessageInvokerInterceptor)

Aggregations

CounterRepository (org.apache.cxf.management.counters.CounterRepository)6 Bus (org.apache.cxf.Bus)5 ObjectName (javax.management.ObjectName)3 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)2 InstrumentationManagerImpl (org.apache.cxf.management.jmx.InstrumentationManagerImpl)2 Test (org.junit.Test)2 Properties (java.util.Properties)1 MBeanServer (javax.management.MBeanServer)1 Endpoint (javax.xml.ws.Endpoint)1 AbstractFeature (org.apache.cxf.feature.AbstractFeature)1 Feature (org.apache.cxf.feature.Feature)1 Counter (org.apache.cxf.management.counters.Counter)1 ResponseTimeMessageInInterceptor (org.apache.cxf.management.interceptor.ResponseTimeMessageInInterceptor)1 ResponseTimeMessageInvokerInterceptor (org.apache.cxf.management.interceptor.ResponseTimeMessageInvokerInterceptor)1 ResponseTimeMessageOutInterceptor (org.apache.cxf.management.interceptor.ResponseTimeMessageOutInterceptor)1 Greeter (org.apache.hello_world_soap_http.Greeter)1 SOAPService (org.apache.hello_world_soap_http.SOAPService)1 OpenEjbConfiguration (org.apache.openejb.assembler.classic.OpenEjbConfiguration)1 ServiceInfo (org.apache.openejb.assembler.classic.ServiceInfo)1 ServiceConfiguration (org.apache.openejb.assembler.classic.util.ServiceConfiguration)1