|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.hivemind.management.mbeans; |
|
16 |
| |
|
17 |
| import javax.management.Attribute; |
|
18 |
| import javax.management.AttributeList; |
|
19 |
| import javax.management.AttributeNotFoundException; |
|
20 |
| import javax.management.DynamicMBean; |
|
21 |
| import javax.management.InvalidAttributeValueException; |
|
22 |
| import javax.management.MBeanAttributeInfo; |
|
23 |
| import javax.management.MBeanConstructorInfo; |
|
24 |
| import javax.management.MBeanException; |
|
25 |
| import javax.management.MBeanInfo; |
|
26 |
| import javax.management.MBeanNotificationInfo; |
|
27 |
| import javax.management.MBeanOperationInfo; |
|
28 |
| import javax.management.MBeanRegistration; |
|
29 |
| import javax.management.MBeanServer; |
|
30 |
| import javax.management.ObjectName; |
|
31 |
| import javax.management.ReflectionException; |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| public abstract class AbstractDynamicMBean implements MBeanRegistration, DynamicMBean |
|
41 |
| { |
|
42 |
| |
|
43 |
| private MBeanInfo _mBeanInfo; |
|
44 |
| |
|
45 |
| private MBeanServer _mbeanServer; |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
7
| public MBeanInfo getMBeanInfo()
|
|
51 |
| { |
|
52 |
7
| if (_mBeanInfo == null)
|
|
53 |
3
| setMBeanInfo(createMBeanInfo());
|
|
54 |
7
| return _mBeanInfo;
|
|
55 |
| } |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
3
| protected void setMBeanInfo(MBeanInfo info)
|
|
64 |
| { |
|
65 |
3
| _mBeanInfo = info;
|
|
66 |
| } |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
3
| private MBeanInfo createMBeanInfo()
|
|
74 |
| { |
|
75 |
3
| MBeanAttributeInfo attrs[] = createMBeanAttributeInfo();
|
|
76 |
3
| MBeanConstructorInfo ctors[] = createMBeanConstructorInfo();
|
|
77 |
3
| MBeanOperationInfo opers[] = createMBeanOperationInfo();
|
|
78 |
3
| MBeanNotificationInfo notifs[] = createMBeanNotificationInfo();
|
|
79 |
3
| String className = getMBeanClassName();
|
|
80 |
3
| String description = getMBeanDescription();
|
|
81 |
3
| return new MBeanInfo(className, description, attrs, ctors, opers, notifs);
|
|
82 |
| } |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
0
| protected MBeanAttributeInfo[] createMBeanAttributeInfo()
|
|
88 |
| { |
|
89 |
0
| return null;
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
2
| protected MBeanConstructorInfo[] createMBeanConstructorInfo()
|
|
96 |
| { |
|
97 |
2
| return null;
|
|
98 |
| } |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
1
| protected MBeanOperationInfo[] createMBeanOperationInfo()
|
|
105 |
| { |
|
106 |
1
| return null;
|
|
107 |
| } |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
2
| protected MBeanNotificationInfo[] createMBeanNotificationInfo()
|
|
114 |
| { |
|
115 |
2
| return null;
|
|
116 |
| } |
|
117 |
| |
|
118 |
3
| protected String getMBeanClassName()
|
|
119 |
| { |
|
120 |
3
| return getClass().getName();
|
|
121 |
| } |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
3
| protected String getMBeanDescription()
|
|
127 |
| { |
|
128 |
3
| return null;
|
|
129 |
| } |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
0
| public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
|
|
135 |
| ReflectionException |
|
136 |
| { |
|
137 |
0
| return null;
|
|
138 |
| } |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
0
| public void setAttribute(Attribute attribute) throws AttributeNotFoundException,
|
|
144 |
| InvalidAttributeValueException, MBeanException, ReflectionException |
|
145 |
| { |
|
146 |
| } |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
1
| public AttributeList getAttributes(String[] attributes)
|
|
154 |
| { |
|
155 |
1
| AttributeList list = new AttributeList();
|
|
156 |
1
| if (attributes != null)
|
|
157 |
| { |
|
158 |
1
| for (int i = 0; i < attributes.length; i++)
|
|
159 |
| { |
|
160 |
2
| String attribute = attributes[i];
|
|
161 |
2
| try
|
|
162 |
| { |
|
163 |
2
| Object result = getAttribute(attribute);
|
|
164 |
2
| list.add(new Attribute(attribute, result));
|
|
165 |
| } |
|
166 |
| catch (AttributeNotFoundException ignored) |
|
167 |
| { |
|
168 |
| } |
|
169 |
| catch (MBeanException ignored) |
|
170 |
| { |
|
171 |
| } |
|
172 |
| catch (ReflectionException ignored) |
|
173 |
| { |
|
174 |
| } |
|
175 |
| } |
|
176 |
| |
|
177 |
| } |
|
178 |
1
| return list;
|
|
179 |
| } |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
1
| public AttributeList setAttributes(AttributeList attributes)
|
|
185 |
| { |
|
186 |
1
| AttributeList list = new AttributeList();
|
|
187 |
| |
|
188 |
1
| if (attributes != null)
|
|
189 |
| { |
|
190 |
1
| for (int i = 0; i < attributes.size(); ++i)
|
|
191 |
| { |
|
192 |
2
| Attribute attribute = (Attribute) attributes.get(i);
|
|
193 |
2
| try
|
|
194 |
| { |
|
195 |
2
| setAttribute(attribute);
|
|
196 |
0
| list.add(attribute);
|
|
197 |
| } |
|
198 |
| catch (AttributeNotFoundException ignored) |
|
199 |
| { |
|
200 |
| } |
|
201 |
| catch (InvalidAttributeValueException ignored) |
|
202 |
| { |
|
203 |
| } |
|
204 |
| catch (MBeanException ignored) |
|
205 |
| { |
|
206 |
| } |
|
207 |
| catch (ReflectionException ignored) |
|
208 |
| { |
|
209 |
| } |
|
210 |
| } |
|
211 |
| } |
|
212 |
| |
|
213 |
1
| return list;
|
|
214 |
| } |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
0
| public Object invoke(String method, Object[] arguments, String[] params) throws MBeanException,
|
|
221 |
| ReflectionException |
|
222 |
| { |
|
223 |
0
| return null;
|
|
224 |
| } |
|
225 |
| |
|
226 |
7
| public ObjectName preRegister(MBeanServer mbeanserver, ObjectName objectname)
|
|
227 |
| { |
|
228 |
7
| _mbeanServer = mbeanserver;
|
|
229 |
7
| return objectname;
|
|
230 |
| } |
|
231 |
| |
|
232 |
1
| public void postRegister(Boolean registrationDone)
|
|
233 |
| { |
|
234 |
| } |
|
235 |
| |
|
236 |
1
| public void preDeregister() throws Exception
|
|
237 |
| { |
|
238 |
| } |
|
239 |
| |
|
240 |
1
| public void postDeregister()
|
|
241 |
| { |
|
242 |
| } |
|
243 |
| |
|
244 |
9
| protected MBeanServer getMBeanServer()
|
|
245 |
| { |
|
246 |
9
| return _mbeanServer;
|
|
247 |
| } |
|
248 |
| |
|
249 |
| |
|
250 |
| } |