use of javax.management.remote.JMXConnector in project Activiti by Activiti.
the class JobExecutorJMXClientTest method testJobExecutorJMXClient.
@Test
public void testJobExecutorJMXClient() throws InterruptedException, IOException, MalformedObjectNameException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
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");
processEngineConfig.buildProcessEngine();
// wait for jmx server to come up
Thread.sleep(500);
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName jobExecutorBeanName = new ObjectName("org.activiti.jmx.Mbeans:type=JobExecutor");
processEngineConfig.getJobExecutor().shutdown();
// first check that job executor is not activated and correctly reported as being inactive
assertFalse(processEngineConfig.isJobExecutorActivate());
assertFalse((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
// now activate it remotely
mbsc.invoke(jobExecutorBeanName, "setJobExecutorActivate", new Boolean[] { true }, new String[] { Boolean.class.getName() });
// check if it has the effect and correctly reported
// assertTrue(processEngineConfig.getJobExecutor().isActive());
assertTrue((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
//agani disable and check it
mbsc.invoke(jobExecutorBeanName, "setJobExecutorActivate", new Boolean[] { false }, new String[] { Boolean.class.getName() });
// check if it has the effect and correctly reported
assertFalse(processEngineConfig.isJobExecutorActivate());
assertFalse((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
}
use of javax.management.remote.JMXConnector in project midpoint by Evolveum.
the class RemoteNodesManager method getSchedulerBean.
private QuartzSchedulerMBean getSchedulerBean(NodeType node, Holder<JMXConnector> connectorHolder, OperationResult result) {
String nodeName = node.getNodeIdentifier();
String address = node.getHostname() + ":" + node.getJmxPort();
try {
JMXConnector connector = connectViaJmx(address);
connectorHolder.setValue(connector);
MBeanServerConnection serverConnection = connector.getMBeanServerConnection();
QuartzSchedulerMBean bean = getMBeanProxy(nodeName, serverConnection);
if (bean == null) {
String message = "Cannot connect to the Quartz Scheduler bean at remote node " + nodeName + " at " + address + " because the JMX object for scheduler cannot be found on that node.";
LOGGER.warn("{}", message);
result.recordFatalError(message);
}
return bean;
} catch (IOException | MalformedObjectNameException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the quartz scheduler bean at remote node {} at {}", e, nodeName, address);
result.recordFatalError("Cannot connect to the quartz scheduler bean at remote node " + nodeName + " at " + address + ": " + e.getMessage(), e);
return null;
}
}
use of javax.management.remote.JMXConnector in project midpoint by Evolveum.
the class RemoteNodesManager method stopRemoteScheduler.
public void stopRemoteScheduler(String nodeIdentifier, OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(RemoteNodesManager.class.getName() + ".stopRemoteScheduler");
result.addParam("nodeIdentifier", nodeIdentifier);
NodeType node = getNode(nodeIdentifier, result);
if (node == null) {
return;
}
String nodeName = node.getNodeIdentifier();
String address = node.getHostname() + ":" + node.getJmxPort();
JMXConnector connector = null;
try {
MBeanServerConnection mbsc;
try {
connector = connectViaJmx(address);
mbsc = connector.getMBeanServerConnection();
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the remote node {} at {}", e, nodeName, address);
result.recordFatalError("Cannot connect to the remote node " + nodeName + " at " + address + ": " + e.getMessage(), e);
return;
}
try {
QuartzSchedulerMBean mbeanProxy = getMBeanProxy(nodeName, mbsc);
if (mbeanProxy != null) {
mbeanProxy.standby();
result.recordSuccess();
} else {
result.recordWarning("Cannot stop the scheduler on node " + nodeName + " at " + address + " because the JMX object for scheduler cannot be found on that node.");
}
return;
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot put remote scheduler into standby mode; remote node {} at {}", e, nodeName, address);
result.recordFatalError("Cannot put remote scheduler " + nodeName + " at " + address + " into standby mode: " + e.getMessage());
return;
}
} finally {
try {
if (connector != null) {
connector.close();
}
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Cannot close JMX connection to {}", e, address);
}
}
}
use of javax.management.remote.JMXConnector in project midpoint by Evolveum.
the class RemoteNodesManager method redirectTaskToNode.
public void redirectTaskToNode(@NotNull Task task, @NotNull NodeType node, @NotNull OperationResult result) {
LOGGER.trace("Trying to schedule task {} on {}", task, node.getNodeIdentifier());
Holder<JMXConnector> connectorHolder = new Holder<>();
try {
QuartzSchedulerMBean mbeanProxy = getSchedulerBean(node, connectorHolder, result);
if (mbeanProxy != null) {
try {
createStarterJobIfNeeded();
mbeanProxy.triggerJob(STARTER_JOB_KEY.getName(), STARTER_JOB_KEY.getGroup(), Collections.singletonMap(JobStarter.TASK_OID, task.getOid()));
LOGGER.debug("Successfully requested start of " + task + " at " + getClusterManager().dumpNodeInfo(node));
result.recordSuccessIfUnknown();
} catch (Exception e) {
// necessary because of mbeanProxy
String message = "Cannot schedule " + task + " at " + getClusterManager().dumpNodeInfo(node);
LoggingUtils.logUnexpectedException(LOGGER, message, e);
result.recordFatalError(message + ":" + e.getMessage(), e);
}
} else {
LOGGER.warn("Couldn't obtain Quartz MBean so couldn't reschedule task {} on {}", task, node.getNodeIdentifier());
}
} finally {
closeJmxConnection(connectorHolder, getClusterManager().dumpNodeInfo(node));
}
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class Client method run.
public static void run(String url) throws Exception {
final int notifEmittedCnt = 10;
final CountDownLatch counter = new CountDownLatch(notifEmittedCnt);
final Set<Long> seqSet = Collections.synchronizedSet(new HashSet<Long>());
final AtomicBoolean duplNotification = new AtomicBoolean();
JMXServiceURL serverUrl = new JMXServiceURL(url);
ObjectName name = new ObjectName("test", "foo", "bar");
JMXConnector jmxConnector = JMXConnectorFactory.connect(serverUrl);
System.out.println("client connected");
jmxConnector.addConnectionNotificationListener(new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {
System.out.println("connection notification: " + notification);
if (!seqSet.add(notification.getSequenceNumber())) {
duplNotification.set(true);
}
if (notification.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
long lostNotifs = ((Long) ((JMXConnectionNotification) notification).getUserData()).longValue();
for (int i = 0; i < lostNotifs; i++) {
counter.countDown();
}
}
}
}, null, null);
MBeanServerConnection jmxServer = jmxConnector.getMBeanServerConnection();
jmxServer.addNotificationListener(name, new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {
System.out.println("client got: " + notification);
if (!seqSet.add(notification.getSequenceNumber())) {
duplNotification.set(true);
}
counter.countDown();
}
}, null, null);
System.out.println("client invoking foo (" + notifEmittedCnt + " times)");
for (int i = 0; i < notifEmittedCnt; i++) {
System.out.print(".");
jmxServer.invoke(name, "foo", new Object[] {}, new String[] {});
}
System.out.println();
try {
System.out.println("waiting for " + notifEmittedCnt + " notifications to arrive");
if (!counter.await(30, TimeUnit.SECONDS)) {
throw new InterruptedException();
}
if (duplNotification.get()) {
System.out.println("ERROR: received duplicated notifications");
throw new Error("received duplicated notifications");
}
System.out.println("\nshutting down client");
} catch (InterruptedException e) {
System.out.println("ERROR: notification processing thread interrupted");
throw new Error("notification thread interrupted unexpectedly");
}
}
Aggregations