use of javax.management.MBeanServerConnection in project tesb-studio-se by Talend.
the class JMXUtil method rebootCleanAll.
public static void rebootCleanAll() throws Exception {
// need to re connect
MBeanServerConnection mbsc = createJMXconnection();
String SYS_MBEAN = "org.apache.karaf:type=system,name=" + instanceName;
ObjectName objectKar = new ObjectName(SYS_MBEAN);
mbsc.invoke(objectKar, "rebootCleanAll", new Object[] { String.valueOf(0) }, new String[] { STRING });
}
use of javax.management.MBeanServerConnection in project tesb-studio-se by Talend.
the class JMXUtil method reboot.
public static void reboot() throws Exception {
// need to re connect
MBeanServerConnection mbsc = createJMXconnection();
String SYS_MBEAN = "org.apache.karaf:type=system,name=" + instanceName;
ObjectName objectKar = new ObjectName(SYS_MBEAN);
mbsc.invoke(objectKar, "reboot", new Object[] { String.valueOf(0) }, new String[] { STRING });
}
use of javax.management.MBeanServerConnection in project tesb-studio-se by Talend.
the class JMXUtil method halt.
public static void halt() throws Exception {
// need to re connect
MBeanServerConnection mbsc = createJMXconnection();
String SYS_MBEAN = "org.apache.karaf:type=system,name=" + instanceName;
ObjectName objectKar = new ObjectName(SYS_MBEAN);
mbsc.invoke(objectKar, "halt", new Object[] {}, new String[] {});
}
use of javax.management.MBeanServerConnection in project Activiti by Activiti.
the class DeploymentsJMXClientTest method testDeploymentsJmxClient.
@SuppressWarnings("unchecked")
@Test
public void testDeploymentsJmxClient() throws IOException, InterruptedException, MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException, IntrospectionException {
String hostName = Utils.getHostName();
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostName + ":10111/jndi/rmi://" + hostName + ":1099/jmxrmi/activiti");
ProcessEngineConfiguration processEngineConfig = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine processEngine = processEngineConfig.buildProcessEngine();
// wait for jmx server to come up
Thread.sleep(500);
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName deploymentsBeanName = new ObjectName("org.activiti.jmx.Mbeans:type=Deployments");
Thread.sleep(500);
// no process deployed yet
List<List<String>> deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
assertEquals(0, deployments.size());
// deploy process remotely
URL fileName = Thread.currentThread().getContextClassLoader().getResource("org/activiti/management/jmx/trivialProcess.bpmn");
mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
// one process is there now, test remote deployments
deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
assertNotNull(deployments);
assertEquals(1, deployments.size());
assertEquals(3, deployments.get(0).size());
String firstDeploymentId = deployments.get(0).get(0);
// test remote process definition
List<List<String>> pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
assertNotNull(pdList);
assertEquals(1, pdList.size());
assertEquals(5, pdList.get(0).size());
assertNotNull(pdList.get(0).get(0));
assertEquals("My process", pdList.get(0).get(1));
// version
assertEquals("1", pdList.get(0).get(2));
// not suspended
assertEquals("false", pdList.get(0).get(3));
assertEquals("This process to test JMX", pdList.get(0).get(4));
// redeploy the same process
mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
// now there should be two deployments
deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
assertNotNull(deployments);
assertEquals(2, deployments.size());
assertEquals(3, deployments.get(0).size());
assertEquals(3, deployments.get(1).size());
// there should be two process definitions, one with version equals to two
pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
assertNotNull(pdList);
assertEquals(2, pdList.size());
assertEquals(5, pdList.get(0).size());
assertEquals(5, pdList.get(1).size());
// check there is one with version= = 1 and another one with version == 2, other attributed are the same
String pidV2 = null;
String pidV1 = null;
if (pdList.get(0).get(2).equals("1") && pdList.get(1).get(2).equals("2")) {
pidV2 = pdList.get(1).get(0);
pidV1 = pdList.get(0).get(0);
} else if (pdList.get(1).get(2).equals("1") && pdList.get(0).get(2).equals("2")) {
pidV2 = pdList.get(0).get(0);
pidV1 = pdList.get(1).get(0);
} else
fail("there should one process definition with version == 1 and another one with version == 2. It is not the case");
assertNotNull(pdList.get(0).get(0));
assertNotNull(pdList.get(1).get(0));
assertEquals("My process", pdList.get(0).get(1));
assertEquals("My process", pdList.get(1).get(1));
// not suspended
assertEquals("false", pdList.get(0).get(3));
// not suspended
assertEquals("false", pdList.get(1).get(3));
assertEquals("This process to test JMX", pdList.get(0).get(4));
assertEquals("This process to test JMX", pdList.get(1).get(4));
//suspend the one with version == 2
mbsc.invoke(deploymentsBeanName, "suspendProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
RepositoryService repositoryService = processEngine.getRepositoryService();
// test if it is realy suspended and not the other one
assertTrue(repositoryService.getProcessDefinition(pidV2).isSuspended());
assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
// test if it is reported as suspended and not the other one
List<String> pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
assertNotNull(pd);
assertEquals(5, pd.size());
assertEquals("true", pd.get(3));
pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
assertNotNull(pd);
assertEquals(5, pd.size());
assertEquals("false", pd.get(3));
// now reactivate the same suspended process
mbsc.invoke(deploymentsBeanName, "activatedProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
// test if both processes are active again
assertFalse(repositoryService.getProcessDefinition(pidV2).isSuspended());
assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
// test if they are properly reported as activated
pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
assertNotNull(pd);
assertEquals(5, pd.size());
assertEquals("false", pd.get(3));
pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
assertNotNull(pd);
assertEquals(5, pd.size());
assertEquals("false", pd.get(3));
// now undeploy the one with version == 1
mbsc.invoke(deploymentsBeanName, "deleteDeployment", new String[] { firstDeploymentId }, new String[] { String.class.getName() });
// now there should be only one deployment and only one process definition with version 2, first check it with API
assertEquals(1, repositoryService.createDeploymentQuery().count());
assertTrue(!repositoryService.createDeploymentQuery().singleResult().getId().equals(firstDeploymentId));
// check if it is also affected in returned results.
deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
assertNotNull(deployments);
assertEquals(1, deployments.size());
assertEquals(3, deployments.get(0).size());
assertTrue(!deployments.get(0).get(0).equals(firstDeploymentId));
}
use of javax.management.MBeanServerConnection in project ACS by ACS-Community.
the class GCJMXClient method main.
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Must provide 2 arguments: <classname> <interval-in-ms>");
}
final GCJMXClient client = new GCJMXClient(args[0]);
try {
client.connect();
} catch (Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
ObjectName objName = null;
try {
objName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
} catch (MalformedObjectNameException e1) {
System.err.println("bad name?");
System.exit(1);
}
final ObjectName objNameF = objName;
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
MBeanServerConnection con = client.getRemote();
try {
con.invoke(objNameF, "gc", null, null);
System.out.println("Called gc() on remote VM");
} catch (Exception e) {
System.err.println("Couldn't call gc() on remote VM");
}
}
};
timer.scheduleAtFixedRate(task, new Date(), Integer.parseInt(args[1]));
}
Aggregations