use of javax.management.MBeanServerConnection 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.MBeanServerConnection 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.MBeanServerConnection in project jdk8u_jdk by JetBrains.
the class RMIConnector method getConnectionWithSubject.
private MBeanServerConnection getConnectionWithSubject(Subject delegationSubject) {
MBeanServerConnection conn = null;
if (delegationSubject == null) {
if (nullSubjectConnRef == null || (conn = nullSubjectConnRef.get()) == null) {
conn = new RemoteMBeanServerConnection(null);
nullSubjectConnRef = new WeakReference(conn);
}
} else {
WeakReference<MBeanServerConnection> wr = rmbscMap.get(delegationSubject);
if (wr == null || (conn = wr.get()) == null) {
conn = new RemoteMBeanServerConnection(delegationSubject);
rmbscMap.put(delegationSubject, new WeakReference(conn));
}
}
return conn;
}
use of javax.management.MBeanServerConnection in project jdk8u_jdk by JetBrains.
the class TestUtils method makeNotificationEmitter.
/**
* Transfroms a proxy implementing T in a proxy implementing T plus
* NotificationEmitter
*
**/
public static <T> T makeNotificationEmitter(T proxy, Class<T> mbeanInterface) {
if (proxy instanceof NotificationEmitter)
return proxy;
if (proxy == null)
return null;
if (!(proxy instanceof Proxy))
throw new IllegalArgumentException("not a " + Proxy.class.getName());
final Proxy p = (Proxy) proxy;
final InvocationHandler handler = Proxy.getInvocationHandler(proxy);
if (!(handler instanceof MBeanServerInvocationHandler))
throw new IllegalArgumentException("not a JMX Proxy");
final MBeanServerInvocationHandler h = (MBeanServerInvocationHandler) handler;
final ObjectName name = h.getObjectName();
final MBeanServerConnection mbs = h.getMBeanServerConnection();
final boolean isMXBean = h.isMXBean();
final T newProxy;
if (isMXBean)
newProxy = JMX.newMXBeanProxy(mbs, name, mbeanInterface, true);
else
newProxy = JMX.newMBeanProxy(mbs, name, mbeanInterface, true);
return newProxy;
}
use of javax.management.MBeanServerConnection 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