1 /* |
|
2 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test UsingEventService.java 1.10 08/01/22 |
|
26 * @bug 5108776 |
|
27 * @summary Basic test for EventManager. |
|
28 * @author Shanliang JIANG |
|
29 * @run clean UsingEventService |
|
30 * @run build UsingEventService |
|
31 * @run main UsingEventService |
|
32 */ |
|
33 |
|
34 import java.util.HashMap; |
|
35 import java.util.Map; |
|
36 import javax.management.MBeanServer; |
|
37 import javax.management.MBeanServerConnection; |
|
38 import javax.management.MBeanServerFactory; |
|
39 import javax.management.Notification; |
|
40 import javax.management.NotificationListener; |
|
41 import javax.management.ObjectName; |
|
42 import javax.management.event.EventConsumer; |
|
43 import javax.management.remote.JMXConnector; |
|
44 import javax.management.remote.JMXConnectorFactory; |
|
45 import javax.management.remote.JMXConnectorServer; |
|
46 import javax.management.remote.JMXConnectorServerFactory; |
|
47 import javax.management.remote.JMXServiceURL; |
|
48 |
|
49 public class UsingEventService { |
|
50 private static JMXServiceURL url; |
|
51 private static JMXConnectorServer server; |
|
52 private static JMXConnector conn; |
|
53 private static MBeanServerConnection client; |
|
54 |
|
55 public static void main(String[] args) throws Exception { |
|
56 if (System.getProperty("java.version").startsWith("1.5")) { |
|
57 System.out.println(">>> UsingEventService-main not available for JDK1.5, bye"); |
|
58 return; |
|
59 } |
|
60 |
|
61 ObjectName oname = new ObjectName("test:t=t"); |
|
62 Notification n = new Notification("", oname, 0); |
|
63 |
|
64 System.out.println(">>> UsingEventService-main basic tests ..."); |
|
65 MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer(); |
|
66 |
|
67 url = new JMXServiceURL("rmi", null, 0) ; |
|
68 JMXConnectorServer server = |
|
69 JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer); |
|
70 server.start(); |
|
71 url = server.getAddress(); |
|
72 |
|
73 System.out.println(">>> UsingEventService-main test to not use the event service..."); |
|
74 conn = JMXConnectorFactory.connect(url, null); |
|
75 client = conn.getMBeanServerConnection(); |
|
76 |
|
77 System.out.println(">>> UsingEventService-main test to use the event service..."); |
|
78 Map env = new HashMap(1); |
|
79 env.put("jmx.remote.use.event.service", "true"); |
|
80 conn = JMXConnectorFactory.connect(url, env); |
|
81 client = conn.getMBeanServerConnection(); |
|
82 |
|
83 ((EventConsumer)client).subscribe(oname, listener, null, null); |
|
84 |
|
85 System.out.println(">>> UsingEventService-main using event service as expected!"); |
|
86 |
|
87 System.out.println(">>> UsingEventService-main test to use" + |
|
88 " the event service with system property..."); |
|
89 |
|
90 System.setProperty("jmx.remote.use.event.service", "true"); |
|
91 conn = JMXConnectorFactory.connect(url, null); |
|
92 client = conn.getMBeanServerConnection(); |
|
93 |
|
94 ((EventConsumer)client).subscribe(oname, listener, null, null); |
|
95 |
|
96 System.out.println("" + |
|
97 ">>> UsingEventService-main using event service as expected!"); |
|
98 |
|
99 System.out.println(">>> Happy bye bye!"); |
|
100 } |
|
101 |
|
102 private final static NotificationListener listener = new NotificationListener() { |
|
103 public void handleNotification(Notification n, Object hk) { |
|
104 // |
|
105 } |
|
106 }; |
|
107 } |
|