use of javax.management.remote.JMXConnector in project karaf by apache.
the class DeployMojo method deployWithJmx.
protected void deployWithJmx(List<String> locations) throws MojoExecutionException {
try {
JMXServiceURL jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/" + instance);
ArrayList<String> list = new ArrayList<>();
if (user != null)
list.add(user);
if (password != null)
list.add(password);
HashMap env = new HashMap();
String[] credentials = list.toArray(new String[list.size()]);
env.put(JMXConnector.CREDENTIALS, credentials);
JMXConnector jmxConnector = null;
if (credentials.length > 0)
jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, env);
else
jmxConnector = JMXConnectorFactory.connect(jmxServiceURL);
MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
for (String location : locations) {
mBeanServerConnection.invoke(new ObjectName("org.apache.karaf:type=bundle,name=*"), "install", new Object[] { location, true }, new String[] { "java.lang.String", "boolean" });
}
} catch (Exception e) {
throw new MojoExecutionException("Can't deploy using JMX", e);
}
}
use of javax.management.remote.JMXConnector in project wildfly by wildfly.
the class ServiceMBeanSupportTestCase method testSarWithServiceMBeanSupport.
/**
* Tests that invocation on a service deployed within a .sar, inside a .ear without an application.xml, is successful.
*
* @throws Exception
*/
@Test
public void testSarWithServiceMBeanSupport() throws Exception {
// get mbean server
final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials());
final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();
try {
// deploy the unmanaged sar
deployer.deploy(ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME);
// check the unmanaged mbean state
int state = (Integer) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test"), "State");
Assert.assertEquals("Unexpected return state from Test MBean: " + state, ServiceMBean.STARTED, state);
} finally {
// undeploy it
deployer.undeploy(ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME);
}
// check the result of life-cycle methods invocation, using result mbean
// also check that the result mbean received lifecycle notifications
String[] expectedAttributes = new String[] { "CreateServiceInvoked", "StartServiceInvoked", "StopServiceInvoked", "DestroyServiceInvoked", "StartingNotificationReceived", "StartedNotificationReceived", "StoppingNotificationReceived", "StoppedNotificationReceived" };
// each of these attributes should be 'true'
for (String attribute : expectedAttributes) {
Boolean result = (Boolean) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test-result"), attribute);
Assert.assertTrue("Unexpected result for " + attribute + ": " + result, result);
}
}
use of javax.management.remote.JMXConnector in project wildfly by wildfly.
the class JNDIBindingMBeanTestCase method testMBeanStartup.
/**
* Makes sure that the MBeans that are expected to be up and running are accessible.
*
* @throws Exception
* @see https://developer.jboss.org/thread/251092
*/
@Test
public void testMBeanStartup() throws Exception {
// get mbean server
final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials());
try {
final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();
// check the deployed MBeans
for (int i = 1; i <= 9; i++) {
final String mbeanName = "jboss:name=mbean-startup-jndi-bind-" + i;
final Object instance = mBeanServerConnection.getObjectInstance(new ObjectName(mbeanName));
Assert.assertNotNull("No instance returned for MBean: " + mbeanName, instance);
}
} finally {
connector.close();
}
}
use of javax.management.remote.JMXConnector in project wildfly by wildfly.
the class SarInjectionTestCase method testMBean.
@Test
public void testMBean() throws Exception {
final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL());
try {
final MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
final ObjectName objectName = new ObjectName("jboss:name=POJOService");
Assert.assertTrue(2 == (Integer) mbeanServer.getAttribute(objectName, "Count"));
Assert.assertTrue(2 == (Integer) mbeanServer.getAttribute(objectName, "InjectedCount"));
Assert.assertTrue((Boolean) mbeanServer.getAttribute(objectName, "CreateCalled"));
Assert.assertTrue((Boolean) mbeanServer.getAttribute(objectName, "StartCalled"));
Assert.assertFalse((Boolean) mbeanServer.getAttribute(objectName, "StopCalled"));
Assert.assertFalse((Boolean) mbeanServer.getAttribute(objectName, "DestroyCalled"));
} finally {
IoUtils.safeClose(connector);
}
}
use of javax.management.remote.JMXConnector in project voldemort by voldemort.
the class AbstractFailureDetectorTest method assertJmxEquals.
protected void assertJmxEquals(String attributeName, Object attributeValue) throws Exception {
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL("service:jmx:rmi://"), null, ManagementFactory.getPlatformMBeanServer());
cs.start();
JMXConnector cc = null;
try {
cc = JMXConnectorFactory.connect(cs.getAddress());
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
ObjectName objectName = JmxUtils.createObjectName(JmxUtils.getPackageName(failureDetector.getClass()), failureDetector.getClass().getSimpleName());
Object availableNodes = mbsc.getAttribute(objectName, attributeName);
assertEquals(attributeValue, availableNodes);
} finally {
if (cc != null)
cc.close();
cs.stop();
}
}
Aggregations