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