20 * CA 95054 USA or visit www.sun.com if you need additional information or |
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
21 * have any questions. |
21 * have any questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test RMINotifTest.java |
25 * @test |
26 * @bug 7654321 |
26 * @bug 7654321 |
27 * @summary Tests to receive notifications for opened and closed connect |
27 * @summary Tests to receive notifications for opened and closed connections |
28 ions |
|
29 * @author sjiang |
28 * @author sjiang |
30 * @run clean RMINotifTest |
29 * @run clean RMINotifTest |
31 * @run build RMINotifTest |
30 * @run build RMINotifTest |
32 * @run main RMINotifTest |
31 * @run main RMINotifTest classic |
|
32 * @run main RMINotifTest event |
33 */ |
33 */ |
34 |
34 |
35 // java imports |
35 // java imports |
36 // |
36 // |
37 import java.io.IOException; |
37 |
38 import java.net.UnknownHostException; |
38 import java.rmi.RemoteException; |
39 |
39 import java.rmi.registry.LocateRegistry; |
40 import java.rmi.*; |
40 import java.rmi.registry.Registry; |
41 import java.rmi.registry.*; |
41 import java.util.Collections; |
|
42 import java.util.Map; |
42 import java.util.Random; |
43 import java.util.Random; |
43 |
44 import javax.management.MBeanNotificationInfo; |
44 // JMX imports |
45 import javax.management.MBeanServer; |
45 // |
46 import javax.management.MBeanServerConnection; |
46 import javax.management.* ; |
47 import javax.management.MBeanServerFactory; |
47 |
48 import javax.management.Notification; |
48 import javax.management.remote.*; |
49 import javax.management.NotificationBroadcasterSupport; |
49 import javax.management.remote.rmi.*; |
50 import javax.management.NotificationFilterSupport; |
|
51 import javax.management.NotificationListener; |
|
52 import javax.management.ObjectInstance; |
|
53 import javax.management.ObjectName; |
|
54 import javax.management.remote.JMXConnector; |
|
55 import javax.management.remote.JMXConnectorFactory; |
|
56 import javax.management.remote.JMXConnectorServer; |
|
57 import javax.management.remote.JMXConnectorServerFactory; |
50 import javax.management.remote.JMXServiceURL; |
58 import javax.management.remote.JMXServiceURL; |
|
59 import javax.management.remote.rmi.RMIConnectorServer; |
51 |
60 |
52 public class RMINotifTest { |
61 public class RMINotifTest { |
53 |
62 |
54 public static void main(String[] args) { |
63 public static void main(String[] args) { |
|
64 String eventService; |
|
65 if (args[0].equals("classic")) |
|
66 eventService = "false"; |
|
67 else if (args[0].equals("event")) |
|
68 eventService = "true"; |
|
69 else |
|
70 throw new IllegalArgumentException(args[0]); |
|
71 |
55 try { |
72 try { |
56 // create a rmi registry |
73 // create a rmi registry |
57 Registry reg = null; |
74 Registry reg = null; |
58 int port = 6666; |
75 int port = 6666; |
59 final Random r = new Random(); |
76 final Random r = new Random(); |
86 JMXServiceURL url = |
103 JMXServiceURL url = |
87 new JMXServiceURL("rmi", null, port, |
104 new JMXServiceURL("rmi", null, port, |
88 "/jndi/rmi://:" + port + "/server" + port); |
105 "/jndi/rmi://:" + port + "/server" + port); |
89 System.out.println("RMIConnectorServer address " + url); |
106 System.out.println("RMIConnectorServer address " + url); |
90 |
107 |
|
108 Map<String, String> env = Collections.singletonMap( |
|
109 RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE, eventService); |
91 JMXConnectorServer sServer = |
110 JMXConnectorServer sServer = |
92 JMXConnectorServerFactory.newJMXConnectorServer(url, null, |
111 JMXConnectorServerFactory.newJMXConnectorServer(url, env, null); |
93 null); |
|
94 |
112 |
95 ObjectInstance ss = server.registerMBean(sServer, new ObjectName("Default:name=RmiConnectorServer")); |
113 ObjectInstance ss = server.registerMBean(sServer, new ObjectName("Default:name=RmiConnectorServer")); |
96 |
114 |
97 sServer.start(); |
115 sServer.start(); |
98 |
116 |