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 |
|
26 * @bug 6450834 |
|
27 * @summary Forward MBeanRegistration calls |
|
28 * @author JF Denise |
|
29 * @run main RegistrationTest |
|
30 */ |
|
31 |
|
32 import java.io.Serializable; |
|
33 import java.lang.management.ManagementFactory; |
|
34 import javax.management.*; |
|
35 |
|
36 public class RegistrationTest { |
|
37 static boolean preRegisterCalled; |
|
38 static boolean postRegisterCalled; |
|
39 static boolean preDeregisterCalled; |
|
40 static boolean postDeregisterCalled; |
|
41 |
|
42 static void checkResult(boolean expected) throws Exception { |
|
43 if((preRegisterCalled != expected || |
|
44 postRegisterCalled != expected || |
|
45 preDeregisterCalled != expected || |
|
46 postDeregisterCalled != expected)) |
|
47 throw new Exception("Mismatch preRegisterCalled = " |
|
48 + preRegisterCalled + ", postRegisterCalled = " |
|
49 + postRegisterCalled + ", preDeregisterCalled = " |
|
50 + preDeregisterCalled + ", postDeregisterCalled = " |
|
51 + postDeregisterCalled); |
|
52 } |
|
53 static class Wrapped implements MBeanRegistration,Serializable { |
|
54 |
|
55 public ObjectName preRegister(MBeanServer server, ObjectName name) |
|
56 throws Exception { |
|
57 preRegisterCalled = true; |
|
58 return name; |
|
59 } |
|
60 |
|
61 public void postRegister(Boolean registrationDone) { |
|
62 postRegisterCalled = true; |
|
63 } |
|
64 |
|
65 public void preDeregister() throws Exception { |
|
66 preDeregisterCalled = true; |
|
67 } |
|
68 |
|
69 public void postDeregister() { |
|
70 postDeregisterCalled = true; |
|
71 } |
|
72 |
|
73 } |
|
74 |
|
75 public static void main(String[] args) throws Exception { |
|
76 StandardMBean std = new StandardMBean(new Wrapped(), |
|
77 Serializable.class); |
|
78 ObjectName name = ObjectName.valueOf(":type=Test"); |
|
79 ManagementFactory.getPlatformMBeanServer().registerMBean(std,name); |
|
80 ManagementFactory.getPlatformMBeanServer().unregisterMBean(name); |
|
81 checkResult(false); |
|
82 StandardMBean.Options opt = new StandardMBean.Options(); |
|
83 opt.setMBeanRegistrationForwarded(true); |
|
84 std = new StandardMBean(new Wrapped(), |
|
85 Serializable.class, opt ); |
|
86 ManagementFactory.getPlatformMBeanServer().registerMBean(std,name); |
|
87 ManagementFactory.getPlatformMBeanServer().unregisterMBean(name); |
|
88 checkResult(true); |
|
89 System.out.println("Test OK"); |
|
90 } |
|
91 } |
|