PerInterfacepublic final class PerInterface extends Object Per-MBean-interface behavior. A single instance of this class can be shared
by all MBeans of the same kind (Standard MBean or MXBean) that have the same
MBean interface. |
Fields Summary |
---|
private final Class | mbeanInterface | private final MBeanIntrospector | introspector | private final MBeanInfo | mbeanInfo | private final Map | getters | private final Map | setters | private final Map | ops |
Constructors Summary |
---|
PerInterface(Class mbeanInterface, MBeanIntrospector introspector, MBeanAnalyzer analyzer, MBeanInfo mbeanInfo)
this.mbeanInterface = mbeanInterface;
this.introspector = introspector;
this.mbeanInfo = mbeanInfo;
analyzer.visit(new InitMaps());
|
Methods Summary |
---|
java.lang.Object | getAttribute(java.lang.Object resource, java.lang.String attribute, java.lang.Object cookie)
final M cm = getters.get(attribute);
if (cm == null) {
final String msg;
if (setters.containsKey(attribute))
msg = "Write-only attribute: " + attribute;
else
msg = "No such attribute: " + attribute;
throw new AttributeNotFoundException(msg);
}
return introspector.invokeM(cm, resource, (Object[]) null, cookie);
| javax.management.MBeanInfo | getMBeanInfo()
return mbeanInfo;
| java.lang.Class | getMBeanInterface()
return mbeanInterface;
| java.lang.Object | invoke(java.lang.Object resource, java.lang.String operation, java.lang.Object[] params, java.lang.String[] signature, java.lang.Object cookie)
final List<MethodAndSig> list = ops.get(operation);
if (list == null) {
final String msg = "No such operation: " + operation;
return noSuchMethod(msg, resource, operation, params, signature,
cookie);
}
if (signature == null)
signature = new String[0];
MethodAndSig found = null;
for (MethodAndSig mas : list) {
if (Arrays.equals(mas.signature, signature)) {
found = mas;
break;
}
}
if (found == null) {
final String badSig = sigString(signature);
final String msg;
if (list.size() == 1) { // helpful exception message
msg = "Signature mismatch for operation " + operation +
": " + badSig + " should be " +
sigString(list.get(0).signature);
} else {
msg = "Operation " + operation + " exists but not with " +
"this signature: " + badSig;
}
return noSuchMethod(msg, resource, operation, params, signature,
cookie);
}
return introspector.invokeM(found.method, resource, params, cookie);
| boolean | isMXBean()
return introspector.isMXBean();
| private java.lang.Object | noSuchMethod(java.lang.String msg, java.lang.Object resource, java.lang.String operation, java.lang.Object[] params, java.lang.String[] signature, java.lang.Object cookie)
// Construct the exception that we will probably throw
final NoSuchMethodException nsme =
new NoSuchMethodException(operation + sigString(signature));
final ReflectionException exception =
new ReflectionException(nsme, msg);
if (introspector.isMXBean())
throw exception; // No compatibility requirement here
// Is the compatibility property set?
GetPropertyAction act = new GetPropertyAction("jmx.invoke.getters");
String invokeGettersS;
try {
invokeGettersS = AccessController.doPrivileged(act);
} catch (Exception e) {
// We don't expect an exception here but if we get one then
// we'll simply assume that the property is not set.
invokeGettersS = null;
}
if (invokeGettersS == null)
throw exception;
int rest = 0;
Map<String, M> methods = null;
if (signature == null || signature.length == 0) {
if (operation.startsWith("get"))
rest = 3;
else if (operation.startsWith("is"))
rest = 2;
if (rest != 0)
methods = getters;
} else if (signature != null && signature.length == 1 &&
operation.startsWith("set")) {
rest = 3;
methods = setters;
}
if (rest != 0) {
String attrName = operation.substring(rest);
M method = methods.get(attrName);
if (method != null && introspector.getName(method).equals(operation)) {
String[] msig = introspector.getSignature(method);
if ((signature == null && msig.length == 0) ||
Arrays.equals(signature, msig)) {
return introspector.invokeM(method, resource, params, cookie);
}
}
}
throw exception;
| void | setAttribute(java.lang.Object resource, java.lang.String attribute, java.lang.Object value, java.lang.Object cookie)
final M cm = setters.get(attribute);
if (cm == null) {
final String msg;
if (getters.containsKey(attribute))
msg = "Read-only attribute: " + attribute;
else
msg = "No such attribute: " + attribute;
throw new AttributeNotFoundException(msg);
}
introspector.invokeSetter(attribute, cm, resource, value, cookie);
| private java.lang.String | sigString(java.lang.String[] signature)
StringBuilder b = new StringBuilder("(");
if (signature != null) {
for (String s : signature) {
if (b.length() > 1)
b.append(", ");
b.append(s);
}
}
return b.append(")").toString();
|
|