use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class RMIConnector method close.
// allows to do close after setting the flag "terminated" to true.
// It is necessary to avoid a deadlock, see 6296324
private synchronized void close(boolean intern) throws IOException {
final boolean tracing = logger.traceOn();
final boolean debug = logger.debugOn();
final String idstr = (tracing ? "[" + this.toString() + "]" : null);
if (!intern) {
//
if (terminated) {
if (closeException == null) {
if (tracing)
logger.trace("close", idstr + " already closed.");
return;
}
} else {
terminated = true;
}
}
if (closeException != null && tracing) {
//
if (tracing) {
logger.trace("close", idstr + " had failed: " + closeException);
logger.trace("close", idstr + " attempting to close again.");
}
}
String savedConnectionId = null;
if (connected) {
savedConnectionId = connectionId;
}
closeException = null;
if (tracing)
logger.trace("close", idstr + " closing.");
if (communicatorAdmin != null) {
communicatorAdmin.terminate();
}
if (rmiNotifClient != null) {
try {
rmiNotifClient.terminate();
if (tracing)
logger.trace("close", idstr + " RMI Notification client terminated.");
} catch (RuntimeException x) {
closeException = x;
if (tracing)
logger.trace("close", idstr + " Failed to terminate RMI Notification client: " + x);
if (debug)
logger.debug("close", x);
}
}
if (connection != null) {
try {
connection.close();
if (tracing)
logger.trace("close", idstr + " closed.");
} catch (NoSuchObjectException nse) {
// OK, the server maybe closed itself.
} catch (IOException e) {
closeException = e;
if (tracing)
logger.trace("close", idstr + " Failed to close RMIServer: " + e);
if (debug)
logger.debug("close", e);
}
}
// Clean up MBeanServerConnection table
//
rmbscMap.clear();
if (savedConnectionId != null) {
Notification closedNotif = new JMXConnectionNotification(JMXConnectionNotification.CLOSED, this, savedConnectionId, clientNotifSeqNo++, "Client has been closed", null);
sendNotification(closedNotif);
}
//
if (closeException != null) {
if (tracing)
logger.trace("close", idstr + " failed to close: " + closeException);
if (closeException instanceof IOException)
throw (IOException) closeException;
if (closeException instanceof RuntimeException)
throw (RuntimeException) closeException;
final IOException x = new IOException("Failed to close: " + closeException);
throw EnvHelp.initCause(x, closeException);
}
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class JMXConnectorServer method sendNotification.
private void sendNotification(String type, String connectionId, String message, Object userData) {
Notification notif = new JMXConnectionNotification(type, getNotificationSource(), connectionId, nextSequenceNumber(), message, userData);
sendNotification(notif);
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class ScanManagerTest method doTestOperation.
/**
* Test of addNotificationListener method, of class com.sun.jmx.examples.scandir.ScanManager.
*/
private void doTestOperation(ScanManagerMXBean proxy, Call op, EnumSet<ScanState> after, String testName) throws Exception {
System.out.println("doTestOperation: " + testName);
final LinkedBlockingQueue<Notification> queue = new LinkedBlockingQueue<Notification>();
NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
try {
queue.put(notification);
} catch (Exception x) {
System.err.println("Failed to queue notif: " + x);
}
}
};
NotificationFilter filter = null;
Object handback = null;
final ScanState before;
final NotificationEmitter emitter = (NotificationEmitter) proxy;
emitter.addNotificationListener(listener, filter, handback);
before = proxy.getState();
op.call();
try {
final Notification notification = queue.poll(3000, TimeUnit.MILLISECONDS);
assertEquals(AttributeChangeNotification.ATTRIBUTE_CHANGE, notification.getType());
assertEquals(AttributeChangeNotification.class, notification.getClass());
assertEquals(ScanManager.SCAN_MANAGER_NAME, notification.getSource());
AttributeChangeNotification acn = (AttributeChangeNotification) notification;
assertEquals("State", acn.getAttributeName());
assertEquals(ScanState.class.getName(), acn.getAttributeType());
assertEquals(before, ScanState.valueOf((String) acn.getOldValue()));
assertContained(after, ScanState.valueOf((String) acn.getNewValue()));
emitter.removeNotificationListener(listener, filter, handback);
} finally {
try {
op.cancel();
} catch (Exception x) {
System.err.println("Failed to cleanup: " + x);
}
}
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class DirectoryScannerTest method doTestOperation.
private void doTestOperation(DirectoryScannerMXBean proxy, Call op, EnumSet<ScanState> after, String testName) throws Exception {
System.out.println("doTestOperation: " + testName);
final LinkedBlockingQueue<Notification> queue = new LinkedBlockingQueue<Notification>();
NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
try {
queue.put(notification);
} catch (Exception x) {
System.err.println("Failed to queue notif: " + x);
}
}
};
NotificationFilter filter = null;
Object handback = null;
final ScanState before;
final NotificationEmitter emitter = (NotificationEmitter) makeNotificationEmitter(proxy, DirectoryScannerMXBean.class);
emitter.addNotificationListener(listener, filter, handback);
before = proxy.getState();
op.call();
try {
final Notification notification = queue.poll(3000, TimeUnit.MILLISECONDS);
assertEquals(AttributeChangeNotification.ATTRIBUTE_CHANGE, notification.getType());
assertEquals(AttributeChangeNotification.class, notification.getClass());
assertEquals(getObjectName(proxy), notification.getSource());
AttributeChangeNotification acn = (AttributeChangeNotification) notification;
assertEquals("State", acn.getAttributeName());
assertEquals(ScanState.class.getName(), acn.getAttributeType());
assertEquals(before, ScanState.valueOf((String) acn.getOldValue()));
assertContained(after, ScanState.valueOf((String) acn.getNewValue()));
emitter.removeNotificationListener(listener, filter, handback);
} finally {
try {
op.cancel();
} catch (Exception x) {
System.err.println("Failed to cleanup: " + x);
}
}
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class DirectoryScannerTest method testScan.
/**
* Test of scan method, of class com.sun.jmx.examples.scandir.DirectoryScanner.
*/
public void testScan() throws Exception {
System.out.println("scan");
final ScanManagerMXBean manager = ScanManager.register();
try {
final String tmpdir = System.getProperty("java.io.tmpdir");
final ScanDirConfigMXBean config = manager.getConfigurationMBean();
final DirectoryScannerConfig bean = config.addDirectoryScanner("test1", tmpdir, ".*", 0, 0);
config.addDirectoryScanner("test2", tmpdir, ".*", 0, 0);
config.addDirectoryScanner("test3", tmpdir, ".*", 0, 0);
manager.applyConfiguration(true);
final DirectoryScannerMXBean proxy = manager.getDirectoryScanners().get("test1");
final Call op = new Call() {
public void call() throws Exception {
final BlockingQueue<Notification> queue = new LinkedBlockingQueue<Notification>();
final NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
try {
queue.put(notification);
} catch (Exception e) {
e.printStackTrace();
}
}
};
manager.start();
while (true) {
final Notification n = queue.poll(10, TimeUnit.SECONDS);
if (n == null)
break;
final AttributeChangeNotification at = (AttributeChangeNotification) n;
if (RUNNING == ScanState.valueOf((String) at.getNewValue()))
break;
else {
System.err.println("New state: " + (String) at.getNewValue() + " isn't " + RUNNING);
}
}
assertContained(EnumSet.of(SCHEDULED, RUNNING, COMPLETED), proxy.getState());
}
public void cancel() throws Exception {
manager.stop();
}
};
doTestOperation(proxy, op, EnumSet.of(RUNNING, SCHEDULED, COMPLETED), "scan");
} catch (Exception x) {
x.printStackTrace();
throw x;
} finally {
try {
manager.stop();
} catch (Exception x) {
System.err.println("Failed to stop: " + x);
}
try {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
} catch (Exception x) {
System.err.println("Failed to cleanup: " + x);
}
}
}
Aggregations