use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class NotifReconnectDeadlockTest method main.
public static void main(String[] args) throws Exception {
System.out.println(">>> Tests reconnection done by a fetching notif thread.");
ObjectName oname = new ObjectName("Default:name=NotificationEmitter");
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
Map env = new HashMap(2);
env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));
final MBeanServer mbs = MBeanServerFactory.newMBeanServer();
mbs.registerMBean(new NotificationEmitter(), oname);
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
server.start();
JMXServiceURL addr = server.getAddress();
JMXConnector client = JMXConnectorFactory.connect(addr, env);
// let pass the first client open notif if there is
Thread.sleep(100);
client.getMBeanServerConnection().addNotificationListener(oname, listener, null, null);
client.addConnectionNotificationListener(listener, null, null);
// max test time: 2 minutes
final long end = System.currentTimeMillis() + 120000;
synchronized (lock) {
while (clientState == null && System.currentTimeMillis() < end) {
mbs.invoke(oname, "sendNotifications", new Object[] { new Notification("MyType", "", 0) }, new String[] { "javax.management.Notification" });
try {
lock.wait(10);
} catch (Exception e) {
}
}
}
if (clientState == null) {
throw new RuntimeException("No reconnection happened, need to reconfigure the test.");
} else if (JMXConnectionNotification.FAILED.equals(clientState) || JMXConnectionNotification.CLOSED.equals(clientState)) {
throw new RuntimeException("Failed to reconnect.");
}
System.out.println(">>> Passed!");
client.removeConnectionNotificationListener(listener);
client.close();
server.stop();
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class NotificationEmissionTest method checkNotifs.
public int checkNotifs(int size, List<Notification> received, List<ObjectName> expected) {
if (received.size() != size) {
echo("Error: expecting " + size + " notifications, got " + received.size());
return 1;
} else {
for (Notification n : received) {
echo("Received notification: " + n);
if (!n.getType().equals("nb")) {
echo("Notification type must be \"nb\"");
return 1;
}
ObjectName o = (ObjectName) n.getSource();
int index = (int) n.getSequenceNumber();
ObjectName nb = expected.get(index);
if (!o.equals(nb)) {
echo("Notification source must be " + nb);
return 1;
}
}
}
return 0;
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class NotificationSender method sendNotifs.
public void sendNotifs(String type, int count) {
for (int i = 0; i < count; i++) {
Notification n = new Notification(type, this, newSeqNo());
sendNotification(n);
}
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class SubjectDelegation1Test method main.
public static void main(String[] args) throws Exception {
// Check for supported operating systems: Solaris
//
// This test runs only on Solaris due to CR 6285916
//
String osName = System.getProperty("os.name");
System.out.println("os.name = " + osName);
if (!osName.equals("SunOS")) {
System.out.println("This test runs on Solaris only.");
System.out.println("Bye! Bye!");
return;
}
String policyFile = args[0];
String testResult = args[1];
System.out.println("Policy file = " + policyFile);
System.out.println("Expected test result = " + testResult);
JMXConnectorServer jmxcs = null;
JMXConnector jmxc = null;
try {
// Create an RMI registry
//
System.out.println("Start RMI registry...");
Registry reg = null;
int port = 5800;
while (port++ < 6000) {
try {
reg = LocateRegistry.createRegistry(port);
System.out.println("RMI registry running on port " + port);
break;
} catch (RemoteException e) {
// Failed to create RMI registry...
System.out.println("Failed to create RMI registry " + "on port " + port);
}
}
if (reg == null) {
System.exit(1);
}
// Set the default password file
//
final String passwordFile = System.getProperty("test.src") + File.separator + "jmxremote.password";
System.out.println("Password file = " + passwordFile);
// Set policy file
//
final String policy = System.getProperty("test.src") + File.separator + policyFile;
System.out.println("PolicyFile = " + policy);
System.setProperty("java.security.policy", policy);
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// Register the SimpleStandardMBean
//
System.out.println("Create SimpleStandard MBean");
SimpleStandard s = new SimpleStandard("delegate");
mbs.registerMBean(s, new ObjectName("MBeans:type=SimpleStandard"));
// Create Properties containing the username/password entries
//
Properties props = new Properties();
props.setProperty("jmx.remote.x.password.file", passwordFile);
// Initialize environment map to be passed to the connector server
//
System.out.println("Initialize environment map");
HashMap env = new HashMap();
env.put("jmx.remote.authenticator", new JMXPluggableAuthenticator(props));
// Create an RMI connector server
//
System.out.println("Create an RMI connector server");
JMXServiceURL url = new JMXServiceURL("rmi", null, 0, "/jndi/rmi://:" + port + "/server" + port);
jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
jmxcs.start();
// Create an RMI connector client
//
System.out.println("Create an RMI connector client");
HashMap cli_env = new HashMap();
// These credentials must match those in the default password file
//
String[] credentials = new String[] { "monitorRole", "QED" };
cli_env.put("jmx.remote.credentials", credentials);
jmxc = JMXConnectorFactory.connect(url, cli_env);
Subject delegationSubject = new Subject(true, Collections.singleton(new JMXPrincipal("delegate")), Collections.EMPTY_SET, Collections.EMPTY_SET);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(delegationSubject);
// Get domains from MBeanServer
//
System.out.println("Domains:");
String[] domains = mbsc.getDomains();
for (int i = 0; i < domains.length; i++) {
System.out.println("\tDomain[" + i + "] = " + domains[i]);
}
// Get MBean count
//
System.out.println("MBean count = " + mbsc.getMBeanCount());
// Get State attribute
//
String oldState = (String) mbsc.getAttribute(new ObjectName("MBeans:type=SimpleStandard"), "State");
System.out.println("Old State = \"" + oldState + "\"");
// Set State attribute
//
System.out.println("Set State to \"changed state\"");
mbsc.setAttribute(new ObjectName("MBeans:type=SimpleStandard"), new Attribute("State", "changed state"));
// Get State attribute
//
String newState = (String) mbsc.getAttribute(new ObjectName("MBeans:type=SimpleStandard"), "State");
System.out.println("New State = \"" + newState + "\"");
if (!newState.equals("changed state")) {
System.out.println("Invalid State = \"" + newState + "\"");
System.exit(1);
}
// Add notification listener on SimpleStandard MBean
//
System.out.println("Add notification listener...");
mbsc.addNotificationListener(new ObjectName("MBeans:type=SimpleStandard"), new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
System.out.println("Received notification: " + notification);
}
}, null, null);
// Unregister SimpleStandard MBean
//
System.out.println("Unregister SimpleStandard MBean...");
mbsc.unregisterMBean(new ObjectName("MBeans:type=SimpleStandard"));
} catch (SecurityException e) {
if (testResult.equals("ko")) {
System.out.println("Got expected security exception = " + e);
} else {
System.out.println("Got unexpected security exception = " + e);
e.printStackTrace();
throw e;
}
} catch (Exception e) {
System.out.println("Unexpected exception caught = " + e);
e.printStackTrace();
throw e;
} finally {
//
if (jmxc != null)
jmxc.close();
//
if (jmxcs != null)
jmxcs.stop();
// Say goodbye
//
System.out.println("Bye! Bye!");
}
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class NotificationBufferCreationTest method dotest.
private static void dotest(String protocol, NotificationSender s, ObjectName notifierName) throws Exception {
JMXConnector client = null;
JMXConnectorServer server = null;
JMXServiceURL u = null;
try {
u = new JMXServiceURL(protocol, null, 0);
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
checkNotifier(s, 0, "new ConnectorServer");
server.start();
checkNotifier(s, 0, "ConnectorServer start");
JMXServiceURL addr = server.getAddress();
client = JMXConnectorFactory.newJMXConnector(addr, null);
checkNotifier(s, 0, "new Connector");
client.connect(null);
checkNotifier(s, 0, "Connector connect");
MBeanServerConnection mbsc = client.getMBeanServerConnection();
final NotificationListener dummyListener = new NotificationListener() {
public void handleNotification(Notification n, Object o) {
// do nothing
return;
}
};
mbsc.addNotificationListener(notifierName, dummyListener, null, null);
// 1 Listener is expected to be added by the ServerNotifForwader
checkNotifier(s, 1, "addNotificationListener");
mbsc.removeNotificationListener(notifierName, dummyListener);
System.out.println("Test OK for " + protocol);
} catch (MalformedURLException e) {
System.out.println("Skipping URL " + u);
} finally {
if (client != null)
client.close();
if (server != null)
server.stop();
}
}
Aggregations