下面列出了javax.management.MBeanOperationInfo#getName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Gets method by operation info.
*
* @param op MBean operation info.
* @return Method.
* @throws ClassNotFoundException Thrown if parameter type is unknown.
* @throws SecurityException Thrown if method access is not allowed.
*/
private Method getMethod(MBeanOperationInfo op) throws ClassNotFoundException, SecurityException {
String mtdName = op.getName();
MBeanParameterInfo[] signature = op.getSignature();
Class<?>[] params = new Class<?>[signature.length];
for (int i = 0; i < signature.length; i++) {
// Parameter type is either a primitive type or class. Try both.
Class<?> type = primCls.get(signature[i].getType().toLowerCase());
if (type == null)
type = Class.forName(signature[i].getType());
params[i] = type;
}
return findMethod(getMBeanInterface(), mtdName, params);
}
public OperationKey(final MBeanOperationInfo info) {
checkNotNull(info);
this.name = info.getName();
ImmutableList.Builder<String> builder = ImmutableList.builder();
for (MBeanParameterInfo pinfo : info.getSignature()) {
builder.add(pinfo.getType());
}
this.types = builder.build();
}
public ReflectionMBeanOperation(final MBeanOperationInfo info,
final Supplier target,
final Method method)
{
this.info = checkNotNull(info);
this.name = info.getName();
this.key = new OperationKey(info);
this.target = checkNotNull(target);
this.method = checkNotNull(method);
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
@Override
public LineRenderer renderer(Iterator<MBeanInfo> stream) {
List<LineRenderer> renderers = new ArrayList<LineRenderer>();
while (stream.hasNext()) {
MBeanInfo info = stream.next();
//
TreeElement root = new TreeElement(info.getClassName());
// Descriptor
TableElement descriptor = new TableElement().
overflow(Overflow.HIDDEN).
rightCellPadding(1);
Descriptor descriptorInfo = info.getDescriptor();
if (descriptorInfo != null) {
for (String fieldName : descriptorInfo.getFieldNames()) {
String fieldValue = String.valueOf(descriptorInfo.getFieldValue(fieldName));
descriptor.row(fieldName, fieldValue);
}
}
// Attributes
TableElement attributes = new TableElement().
overflow(Overflow.HIDDEN).
rightCellPadding(1).
add(new RowElement().style(Decoration.bold.fg(Color.black).bg(Color.white)).add("NAME", "TYPE", "DESCRIPTION"));
for (MBeanAttributeInfo attributeInfo : info.getAttributes()) {
attributes.row(attributeInfo.getName(), attributeInfo.getType(), attributeInfo.getDescription());
}
// Operations
TreeElement operations = new TreeElement("Operations");
for (MBeanOperationInfo operationInfo : info.getOperations()) {
TableElement signature = new TableElement().
overflow(Overflow.HIDDEN).
rightCellPadding(1);
MBeanParameterInfo[] parameterInfos = operationInfo.getSignature();
for (MBeanParameterInfo parameterInfo : parameterInfos) {
signature.row(parameterInfo.getName(), parameterInfo.getType(), parameterInfo.getDescription());
}
TreeElement operation = new TreeElement(operationInfo.getName());
String impact;
switch (operationInfo.getImpact()) {
case MBeanOperationInfo.ACTION:
impact = "ACTION";
break;
case MBeanOperationInfo.INFO:
impact = "INFO";
break;
case MBeanOperationInfo.ACTION_INFO:
impact = "ACTION_INFO";
break;
default:
impact = "UNKNOWN";
}
operation.addChild(new TableElement().
add(
new RowElement().add("Type: ", operationInfo.getReturnType()),
new RowElement().add("Description: ", operationInfo.getDescription()),
new RowElement().add("Impact: ", impact),
new RowElement().add(new LabelElement("Signature: "), signature)
)
);
operations.addChild(operation);
}
//
root.addChild(
new TableElement().leftCellPadding(1).overflow(Overflow.HIDDEN).
row("ClassName", info.getClassName()).
row("Description", info.getDescription()
)
);
root.addChild(new TreeElement("Descriptor").addChild(descriptor));
root.addChild(new TreeElement("Attributes").addChild(attributes));
root.addChild(operations);
//
renderers.add(root.renderer());
}
return LineRenderer.vertical(renderers);
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}
private static void test(Object child, String name, boolean mxbean)
throws Exception {
final ObjectName childName =
new ObjectName("test:type=Child,name="+name);
final MBeanServer server =
ManagementFactory.getPlatformMBeanServer();
server.registerMBean(child,childName);
try {
final MBeanInfo info = server.getMBeanInfo(childName);
System.out.println(name+": " + info.getDescriptor());
final int len = info.getOperations().length;
if (len == OPCOUNT) {
System.out.println(name+": OK, only "+OPCOUNT+
" operations here...");
} else {
final String qual = (len>OPCOUNT)?"many":"few";
System.err.println(name+": Too "+qual+" foos! Found "+
len+", expected "+OPCOUNT);
for (MBeanOperationInfo op : info.getOperations()) {
System.err.println("public "+op.getReturnType()+" "+
op.getName()+"();");
}
throw new RuntimeException("Too " + qual +
" foos for "+name);
}
final Descriptor d = info.getDescriptor();
final String mxstr = String.valueOf(d.getFieldValue("mxbean"));
final boolean mxb =
(mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue();
System.out.println(name+": mxbean="+mxb);
if (mxbean && !mxb)
throw new AssertionError("MXBean is not OpenMBean?");
for (MBeanOperationInfo mboi : info.getOperations()) {
// Sanity check
if (mxbean && !mboi.getName().equals("foo")) {
// The spec doesn't guarantee that the MBeanOperationInfo
// of an MXBean will be an OpenMBeanOperationInfo, and in
// some circumstances in our implementation it will not.
// However, in thsi tests, for all methods but foo(),
// it should.
//
if (!(mboi instanceof OpenMBeanOperationInfo))
throw new AssertionError("Operation "+mboi.getName()+
"() is not Open?");
}
final String exp = EXPECTED_TYPES.get(mboi.getName());
// For MXBeans, we need to compare 'exp' with the original
// type - because mboi.getReturnType() returns the OpenType
//
String type = (String)mboi.getDescriptor().
getFieldValue("originalType");
if (type == null) type = mboi.getReturnType();
if (type.equals(exp)) continue;
System.err.println("Bad return type for "+
mboi.getName()+"! Found "+type+
", expected "+exp);
throw new RuntimeException("Bad return type for "+
mboi.getName());
}
} finally {
server.unregisterMBean(childName);
}
}