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();
}
}
}
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);
}
}
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();
}
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);
}
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);
}
}
}
Aggregations