|
1 /* |
|
2 * @test UsingEventService.java 1.10 08/01/22 |
|
3 * @bug 5108776 |
|
4 * @summary Basic test for EventManager. |
|
5 * @author Shanliang JIANG |
|
6 * @run clean UsingEventService |
|
7 * @run build UsingEventService |
|
8 * @run main UsingEventService |
|
9 */ |
|
10 |
|
11 import java.util.HashMap; |
|
12 import java.util.Map; |
|
13 import javax.management.MBeanServer; |
|
14 import javax.management.MBeanServerConnection; |
|
15 import javax.management.MBeanServerFactory; |
|
16 import javax.management.Notification; |
|
17 import javax.management.NotificationListener; |
|
18 import javax.management.ObjectName; |
|
19 import javax.management.event.EventConsumer; |
|
20 import javax.management.remote.JMXConnector; |
|
21 import javax.management.remote.JMXConnectorFactory; |
|
22 import javax.management.remote.JMXConnectorServer; |
|
23 import javax.management.remote.JMXConnectorServerFactory; |
|
24 import javax.management.remote.JMXServiceURL; |
|
25 |
|
26 public class UsingEventService { |
|
27 private static JMXServiceURL url; |
|
28 private static JMXConnectorServer server; |
|
29 private static JMXConnector conn; |
|
30 private static MBeanServerConnection client; |
|
31 |
|
32 public static void main(String[] args) throws Exception { |
|
33 if (System.getProperty("java.version").startsWith("1.5")) { |
|
34 System.out.println(">>> UsingEventService-main not available for JDK1.5, bye"); |
|
35 return; |
|
36 } |
|
37 |
|
38 ObjectName oname = new ObjectName("test:t=t"); |
|
39 Notification n = new Notification("", oname, 0); |
|
40 |
|
41 System.out.println(">>> UsingEventService-main basic tests ..."); |
|
42 MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer(); |
|
43 |
|
44 url = new JMXServiceURL("rmi", null, 0) ; |
|
45 JMXConnectorServer server = |
|
46 JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer); |
|
47 server.start(); |
|
48 url = server.getAddress(); |
|
49 |
|
50 System.out.println(">>> UsingEventService-main test to not use the event service..."); |
|
51 conn = JMXConnectorFactory.connect(url, null); |
|
52 client = conn.getMBeanServerConnection(); |
|
53 |
|
54 System.out.println(">>> UsingEventService-main test to use the event service..."); |
|
55 Map env = new HashMap(1); |
|
56 env.put("jmx.remote.use.event.service", "true"); |
|
57 conn = JMXConnectorFactory.connect(url, env); |
|
58 client = conn.getMBeanServerConnection(); |
|
59 |
|
60 ((EventConsumer)client).subscribe(oname, listener, null, null); |
|
61 |
|
62 System.out.println(">>> UsingEventService-main using event service as expected!"); |
|
63 |
|
64 System.out.println(">>> UsingEventService-main test to use" + |
|
65 " the event service with system property..."); |
|
66 |
|
67 System.setProperty("jmx.remote.use.event.service", "true"); |
|
68 conn = JMXConnectorFactory.connect(url, null); |
|
69 client = conn.getMBeanServerConnection(); |
|
70 |
|
71 ((EventConsumer)client).subscribe(oname, listener, null, null); |
|
72 |
|
73 System.out.println("" + |
|
74 ">>> UsingEventService-main using event service as expected!"); |
|
75 |
|
76 System.out.println(">>> Happy bye bye!"); |
|
77 } |
|
78 |
|
79 private final static NotificationListener listener = new NotificationListener() { |
|
80 public void handleNotification(Notification n, Object hk) { |
|
81 // |
|
82 } |
|
83 }; |
|
84 } |