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