author | dfuchs |
Wed, 10 Sep 2008 16:27:13 +0200 | |
changeset 1227 | 4546977d0d66 |
parent 1156 | bbc2d15aaf7a |
permissions | -rw-r--r-- |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
1 |
/* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
4 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
8 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
14 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
18 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
21 |
* have any questions. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
22 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
23 |
/* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
24 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
25 |
* @test DomainCreationTest.java |
1227
4546977d0d66
6746754: jmx namespace: test for leading separator missing
dfuchs
parents:
1156
diff
changeset
|
26 |
* @bug 5072476 |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
27 |
* @summary Test the creation and registration of JMXDomain instances. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
28 |
* @author Daniel Fuchs |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
29 |
* @run clean DomainCreationTest Wombat WombatMBean |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
30 |
* @run build DomainCreationTest Wombat WombatMBean |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
31 |
* @run main DomainCreationTest |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
32 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
33 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
34 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
35 |
import java.util.Collections; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
36 |
import java.util.Map; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
37 |
import java.util.Set; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
38 |
import javax.management.Attribute; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
39 |
import javax.management.AttributeList; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
40 |
import javax.management.AttributeNotFoundException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
41 |
import javax.management.DynamicMBean; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
42 |
import javax.management.InstanceNotFoundException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
43 |
import javax.management.InvalidAttributeValueException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
44 |
import javax.management.MBeanException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
45 |
import javax.management.MBeanInfo; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
46 |
import javax.management.MBeanRegistration; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
47 |
import javax.management.MBeanServer; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
48 |
import javax.management.MBeanServerFactory; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
49 |
import javax.management.NotificationEmitter; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
50 |
import javax.management.ObjectInstance; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
51 |
import javax.management.ObjectName; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
52 |
import javax.management.ReflectionException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
53 |
import javax.management.RuntimeMBeanException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
54 |
import javax.management.RuntimeOperationsException; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
55 |
import javax.management.namespace.JMXDomain; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
56 |
import javax.management.namespace.MBeanServerSupport; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
57 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
58 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
59 |
* Test simple creation/registration of namespace. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
60 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
61 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
62 |
public class DomainCreationTest { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
63 |
private static Map<String,Object> emptyEnvMap() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
64 |
return Collections.emptyMap(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
65 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
66 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
67 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
68 |
public static class LocalDomainRepository |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
69 |
extends MBeanServerSupport { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
70 |
private final MBeanServer server; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
71 |
private final String domain; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
72 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
73 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
74 |
public class DynamicMBeanProxy implements DynamicMBean { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
75 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
76 |
private final MBeanServer server; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
77 |
private final ObjectName name; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
78 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
79 |
public DynamicMBeanProxy(MBeanServer s, ObjectName n) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
80 |
this.server = s; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
81 |
this.name = n; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
82 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
83 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
84 |
public Object getAttribute(String attribute) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
85 |
throws AttributeNotFoundException, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
86 |
MBeanException, ReflectionException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
87 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
88 |
return server.getAttribute(name, attribute); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
89 |
} catch (RuntimeException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
90 |
throw x; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
91 |
} catch (Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
92 |
throw new RuntimeException(x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
93 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
94 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
95 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
96 |
public void setAttribute(Attribute attribute) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
97 |
throws AttributeNotFoundException, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
98 |
InvalidAttributeValueException, MBeanException, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
99 |
ReflectionException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
100 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
101 |
server.setAttribute(name, attribute); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
102 |
} catch (RuntimeException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
103 |
throw x; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
104 |
} catch (Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
105 |
throw new RuntimeException(x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
106 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
107 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
108 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
109 |
public AttributeList getAttributes(String[] attributes) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
110 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
111 |
return server.getAttributes(name, attributes); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
112 |
} catch (RuntimeException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
113 |
throw x; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
114 |
} catch (Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
115 |
throw new RuntimeException(x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
116 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
117 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
118 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
119 |
public AttributeList setAttributes(AttributeList attributes) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
120 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
121 |
return server.setAttributes(name, attributes); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
122 |
} catch (RuntimeException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
123 |
throw x; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
124 |
} catch (Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
125 |
throw new RuntimeException(x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
126 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
127 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
128 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
129 |
public Object invoke(String actionName, Object[] params, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
130 |
String[] signature) throws MBeanException, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
131 |
ReflectionException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
132 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
133 |
return server.invoke(name, actionName, params, signature); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
134 |
} catch (RuntimeException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
135 |
throw x; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
136 |
} catch (Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
137 |
throw new RuntimeException(x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
138 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
139 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
140 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
141 |
public MBeanInfo getMBeanInfo() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
142 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
143 |
return server.getMBeanInfo(name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
144 |
} catch (RuntimeException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
145 |
throw x; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
146 |
} catch (Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
147 |
throw new RuntimeException(x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
148 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
149 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
150 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
151 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
152 |
public LocalDomainRepository(String domain) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
153 |
this.server = MBeanServerFactory.newMBeanServer(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
154 |
this.domain = domain; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
155 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
156 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
157 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
158 |
protected Set<ObjectName> getNames() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
159 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
160 |
final ObjectName name = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
161 |
ObjectName.getInstance(domain+":*"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
162 |
return server.queryNames(name, null); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
163 |
} catch (RuntimeException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
164 |
throw x; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
165 |
} catch (Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
166 |
throw new RuntimeException(x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
167 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
168 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
169 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
170 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
171 |
public DynamicMBean getDynamicMBeanFor(ObjectName name) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
172 |
throws InstanceNotFoundException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
173 |
return new DynamicMBeanProxy(server, name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
174 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
175 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
176 |
@Override |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
177 |
public NotificationEmitter |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
178 |
getNotificationEmitterFor(ObjectName name) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
179 |
throws InstanceNotFoundException { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
180 |
DynamicMBean mbean = getDynamicMBeanFor(name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
181 |
if (mbean instanceof NotificationEmitter) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
182 |
return (NotificationEmitter) mbean; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
183 |
return null; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
184 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
185 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
186 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
187 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
188 |
private static MBeanServer newMBeanServer() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
189 |
return MBeanServerFactory.newMBeanServer(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
190 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
191 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
192 |
public static interface ThingMBean {} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
193 |
public static class Thing implements ThingMBean, MBeanRegistration { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
194 |
public ObjectName preRegister(MBeanServer server, ObjectName name) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
195 |
throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
196 |
if (name == null) return new ObjectName(":type=Thing"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
197 |
else return name; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
198 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
199 |
public void postRegister(Boolean registrationDone) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
200 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
201 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
202 |
public void preDeregister() throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
203 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
204 |
public void postDeregister() { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
205 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
206 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
207 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
208 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
209 |
* Test that it is possible to create a dummy MBean with a null |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
210 |
* ObjectName - this is just a sanity check - as there are already |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
211 |
* other JMX tests that check that. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
212 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
213 |
* @throws java.lang.Exception |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
214 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
215 |
public static void testCreateWithNull() throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
216 |
final MBeanServer server = newMBeanServer(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
217 |
final ObjectInstance oi = server.registerMBean(new Thing(),null); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
218 |
server.unregisterMBean(oi.getObjectName()); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
219 |
System.out.println("testCreateWithNull PASSED"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
220 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
221 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
222 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
223 |
* Check that we can register a JMXNamespace MBean, using its standard |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
224 |
* ObjectName. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
225 |
* @throws java.lang.Exception |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
226 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
227 |
public static void testGoodObjectName() throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
228 |
MBeanServer server = newMBeanServer(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
229 |
final ObjectName name = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
230 |
JMXDomain.getDomainObjectName("gloups"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
231 |
final ObjectInstance oi = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
232 |
server.registerMBean(new JMXDomain( |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
233 |
new LocalDomainRepository("gloups")),name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
234 |
System.out.println("Succesfully registered namespace: "+name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
235 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
236 |
if (! name.equals(oi.getObjectName())) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
237 |
throw new RuntimeException("testGoodObjectName: TEST failed: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
238 |
"namespace registered as: "+ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
239 |
oi.getObjectName()+" expected: "+name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
240 |
} finally { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
241 |
server.unregisterMBean(oi.getObjectName()); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
242 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
243 |
System.out.println("Succesfully unregistered namespace: "+name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
244 |
System.out.println("testGoodObjectName PASSED"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
245 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
246 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
247 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
248 |
* Check that we cannot register a JMXNamespace MBean, if we don't use |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
249 |
* its standard ObjectName. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
250 |
* @throws java.lang.Exception |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
251 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
252 |
public static void testBadObjectName() throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
253 |
MBeanServer server = newMBeanServer(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
254 |
Throwable exp = null; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
255 |
final ObjectName name = new ObjectName("d:k=v"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
256 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
257 |
server.registerMBean(new JMXDomain( |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
258 |
new LocalDomainRepository("d")),name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
259 |
System.out.println("testBadObjectName: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
260 |
"Error: MBean registered, no exception thrown."); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
261 |
} catch(RuntimeMBeanException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
262 |
exp = x.getCause(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
263 |
} catch(Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
264 |
throw new RuntimeException("testBadObjectName: TEST failed: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
265 |
"expected RuntimeMBeanException - got "+ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
266 |
x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
267 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
268 |
if (exp == null) server.unregisterMBean(name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
269 |
if (exp == null) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
270 |
throw new RuntimeException("testBadObjectName: TEST failed: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
271 |
"expected IllegalArgumentException - got none"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
272 |
if (!(exp instanceof IllegalArgumentException)) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
273 |
throw new RuntimeException("testBadObjectName: TEST failed: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
274 |
"expected IllegalArgumentException - got "+ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
275 |
exp.toString(),exp); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
276 |
System.out.println("Got expected exception: "+exp); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
277 |
System.out.println("testBadObjectName PASSED"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
278 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
279 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
280 |
/** |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
281 |
* Check that we cannot register a Domain MBean in a domain that already |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
282 |
* exists. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
283 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
284 |
* @throws java.lang.Exception |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
285 |
*/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
286 |
public static void testBadDomain() throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
287 |
MBeanServer server = newMBeanServer(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
288 |
Throwable exp = null; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
289 |
final ObjectName name = new ObjectName("glips:k=v"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
290 |
server.registerMBean(new Wombat(),name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
291 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
292 |
final ObjectName dname = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
293 |
JMXDomain.getDomainObjectName("glips"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
294 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
295 |
try { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
296 |
server.registerMBean(new JMXDomain( |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
297 |
new LocalDomainRepository("glips")),dname); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
298 |
System.out.println("testBadDomain: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
299 |
"Error: MBean registered, no exception thrown."); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
300 |
} catch(RuntimeOperationsException x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
301 |
exp = x.getCause(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
302 |
} catch(Exception x) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
303 |
throw new RuntimeException("testBadDomain: TEST failed: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
304 |
"expected RuntimeOperationsException - got "+ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
305 |
x); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
306 |
} finally { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
307 |
server.unregisterMBean(name); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
308 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
309 |
if (exp == null) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
310 |
server.unregisterMBean(dname); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
311 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
312 |
if (exp == null) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
313 |
throw new RuntimeException("testBadDomain: TEST failed: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
314 |
"expected IllegalArgumentException - got none"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
315 |
if (!(exp instanceof IllegalArgumentException)) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
316 |
throw new RuntimeException("testBadDomain: TEST failed: " + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
317 |
"expected IllegalArgumentException - got "+ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
318 |
exp.toString(),exp); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
319 |
System.out.println("Got expected exception: "+exp); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
320 |
System.out.println("testBadDomain PASSED"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
321 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
322 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
323 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
324 |
public static void main(String... args) throws Exception { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
325 |
testCreateWithNull(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
326 |
testGoodObjectName(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
327 |
testBadObjectName(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
328 |
testBadDomain(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
329 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff
changeset
|
330 |
} |