44 import javax.management.ListenerNotFoundException; |
44 import javax.management.ListenerNotFoundException; |
45 import javax.management.MBeanException; |
45 import javax.management.MBeanException; |
46 import javax.management.MBeanInfo; |
46 import javax.management.MBeanInfo; |
47 import javax.management.MBeanRegistrationException; |
47 import javax.management.MBeanRegistrationException; |
48 import javax.management.MBeanServerConnection; |
48 import javax.management.MBeanServerConnection; |
49 import javax.management.MalformedObjectNameException; |
|
50 import javax.management.NotCompliantMBeanException; |
49 import javax.management.NotCompliantMBeanException; |
51 import javax.management.NotificationFilter; |
50 import javax.management.NotificationFilter; |
52 import javax.management.NotificationListener; |
51 import javax.management.NotificationListener; |
53 import javax.management.ObjectInstance; |
52 import javax.management.ObjectInstance; |
54 import javax.management.ObjectName; |
53 import javax.management.ObjectName; |
98 * named "X" is mounted in the target namespace "foo//" of a master agent M, |
97 * named "X" is mounted in the target namespace "foo//" of a master agent M, |
99 * the source is S, the target is "foo//" in M, the source name is "X", and |
98 * the source is S, the target is "foo//" in M, the source name is "X", and |
100 * the target name is "foo//X". |
99 * the target name is "foo//X". |
101 * In the case of cascading - such as in NamespaceInterceptor, this method |
100 * In the case of cascading - such as in NamespaceInterceptor, this method |
102 * will convert "foo//X" (the targetName) into "X", the source name. |
101 * will convert "foo//X" (the targetName) into "X", the source name. |
|
102 * @throws IllegalArgumentException if the name cannot be converted. |
103 **/ |
103 **/ |
104 protected abstract ObjectName toSource(ObjectName targetName) |
104 protected abstract ObjectName toSource(ObjectName targetName); |
105 throws MalformedObjectNameException; |
|
106 |
|
107 /** |
105 /** |
108 * Converts a source ObjectName to a target ObjectName. |
106 * Converts a source ObjectName to a target ObjectName. |
109 * (see description of toSource above for explanations) |
107 * (see description of toSource above for explanations) |
110 * In the case of cascading - such as in NamespaceInterceptor, this method |
108 * In the case of cascading - such as in NamespaceInterceptor, this method |
111 * will convert "X" (the sourceName) into "foo//X", the target name. |
109 * will convert "X" (the sourceName) into "foo//X", the target name. |
|
110 * @throws IllegalArgumentException if the name cannot be converted. |
112 **/ |
111 **/ |
113 protected abstract ObjectName toTarget(ObjectName sourceName) |
112 protected abstract ObjectName toTarget(ObjectName sourceName); |
114 throws MalformedObjectNameException; |
|
115 |
113 |
116 /** |
114 /** |
117 * Can be overridden by subclasses to check the validity of a new |
115 * Can be overridden by subclasses to check the validity of a new |
118 * ObjectName used in createMBean or registerMBean. |
116 * ObjectName used in createMBean or registerMBean. |
119 * This method is typically used by subclasses which might require |
117 * This method is typically used by subclasses which might require |
126 } catch (Exception x) { |
124 } catch (Exception x) { |
127 throw new MBeanRegistrationException(x,"Illegal MBean Name"); |
125 throw new MBeanRegistrationException(x,"Illegal MBean Name"); |
128 } |
126 } |
129 } |
127 } |
130 |
128 |
131 // Calls toSource(), Wraps MalformedObjectNameException. |
129 // Calls toSource(), Wraps IllegalArgumentException. |
132 ObjectName toSourceOrRuntime(ObjectName targetName) |
130 ObjectName toSourceOrRuntime(ObjectName targetName) { |
133 throws RuntimeOperationsException { |
|
134 try { |
131 try { |
135 return toSource(targetName); |
132 return toSource(targetName); |
136 } catch (MalformedObjectNameException x) { |
133 } catch (RuntimeException x) { |
137 final IllegalArgumentException x2 = |
134 throw makeCompliantRuntimeException(x); |
138 new IllegalArgumentException(String.valueOf(targetName),x); |
|
139 final RuntimeOperationsException x3 = |
|
140 new RuntimeOperationsException(x2); |
|
141 throw x3; |
|
142 } |
135 } |
143 } |
136 } |
144 |
137 |
145 |
138 |
146 // Wraps given exception if needed. |
139 // Wraps given exception if needed. |
374 if (source == null) return null; |
367 if (source == null) return null; |
375 final ObjectName sourceName = source.getObjectName(); |
368 final ObjectName sourceName = source.getObjectName(); |
376 try { |
369 try { |
377 final ObjectName targetName = toTarget(sourceName); |
370 final ObjectName targetName = toTarget(sourceName); |
378 return new ObjectInstance(targetName,source.getClassName()); |
371 return new ObjectInstance(targetName,source.getClassName()); |
379 } catch (MalformedObjectNameException x) { |
372 } catch (RuntimeException x) { |
380 final IllegalArgumentException x2 = |
373 throw makeCompliantRuntimeException(x); |
381 new IllegalArgumentException(String.valueOf(sourceName),x); |
|
382 final RuntimeOperationsException x3 = |
|
383 new RuntimeOperationsException(x2); |
|
384 throw x3; |
|
385 } |
374 } |
386 } |
375 } |
387 |
376 |
388 // Returns names in the target's context. |
377 // Returns names in the target's context. |
389 Set<ObjectName> processOutputNames(Set<ObjectName> sourceNames) { |
378 Set<ObjectName> processOutputNames(Set<ObjectName> sourceNames) { |