下面列出了怎么用javax.management.openmbean.OpenMBeanOperationInfo的API类实例代码及写法,或者点击链接到github查看源代码。
private OpenMBeanOperationInfo getOperation(String name, OpenMBeanParameterInfo addWildcardChildName, OperationEntry entry) {
ModelNode opNode = entry.getDescriptionProvider().getModelDescription(null);
OpenMBeanParameterInfo[] params = getParameterInfos(opNode);
if (addWildcardChildName != null) {
OpenMBeanParameterInfo[] newParams = new OpenMBeanParameterInfo[params.length + 1];
newParams[0] = addWildcardChildName;
System.arraycopy(params, 0, newParams, 1, params.length);
params = newParams;
}
return new OpenMBeanOperationInfoSupport(
name,
getDescription(opNode),
params,
getReturnType(opNode),
entry.getFlags().contains(Flag.READ_ONLY) ? MBeanOperationInfo.INFO : MBeanOperationInfo.UNKNOWN,
createOperationDescriptor());
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private OpenMBeanOperationInfo greetOpenOperationInfo() {
return new OpenMBeanOperationInfoSupport(
GREET_METHOD_NAME, // 操作方法名称
"greet 方法", // 操作方法描述
of(nameOpenMBeanParameterInfo()), // 操作方法参数信息
SimpleType.STRING, // 操作方法返回类型
ACTION);
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private static MBeanOperationInfo
customize(MBeanOperationInfo oi,
String description,
MBeanParameterInfo[] signature,
int impact) {
if (equal(description, oi.getDescription()) &&
identicalArrays(signature, oi.getSignature()) &&
impact == oi.getImpact())
return oi;
if (oi instanceof OpenMBeanOperationInfo) {
OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
OpenMBeanParameterInfo[] oparams =
paramsToOpenParams(signature);
return new OpenMBeanOperationInfoSupport(oi.getName(),
description,
oparams,
ooi.getReturnOpenType(),
impact,
oi.getDescriptor());
} else {
return new MBeanOperationInfo(oi.getName(),
description,
signature,
oi.getReturnType(),
impact,
oi.getDescriptor());
}
}
private OpenMBeanOperationInfo[] getOperations() {
final boolean root = pathAddress.size() == 0;
//TODO include inherited/global operations?
List<OpenMBeanOperationInfo> ops = new ArrayList<OpenMBeanOperationInfo>();
for (Map.Entry<String, OperationEntry> entry : resourceRegistration.getOperationDescriptions(PathAddress.EMPTY_ADDRESS, false).entrySet()) {
final String opName = entry.getKey();
if (opName.equals(ADD) || opName.equals(DESCRIBE)) {
continue;
}
if (root) {
if (opName.equals(READ_RESOURCE_OPERATION) || opName.equals(READ_ATTRIBUTE_OPERATION) ||
opName.equals(READ_RESOURCE_DESCRIPTION_OPERATION) || opName.equals(READ_CHILDREN_NAMES_OPERATION) ||
opName.equals(READ_CHILDREN_TYPES_OPERATION) || opName.equals(READ_CHILDREN_RESOURCES_OPERATION) ||
opName.equals(READ_OPERATION_NAMES_OPERATION) || opName.equals(READ_OPERATION_DESCRIPTION_OPERATION) ||
opName.equals(READ_RESOURCE_OPERATION) || opName.equals(READ_RESOURCE_OPERATION) ||
opName.equals(WRITE_ATTRIBUTE_OPERATION) || opName.equals(ValidateAddressOperationHandler.OPERATION_NAME) ||
opName.equals(CompositeOperationHandler.NAME) || opName.equals(DeploymentUploadStreamAttachmentHandler.OPERATION_NAME)) {
//Ignore some of the global operations which probably don't make much sense here
continue;
}
}
final OperationEntry opEntry = entry.getValue();
if (mutabilityChecker.mutable(pathAddress) || opEntry.getFlags().contains(Flag.READ_ONLY) || opEntry.getFlags().contains(Flag.RUNTIME_ONLY)) {
ops.add(getOperation(NameConverter.convertToCamelCase(entry.getKey()), null, opEntry));
}
}
addChildAddOperations(ops, resourceRegistration);
return ops.toArray(new OpenMBeanOperationInfo[ops.size()]);
}
private OpenMBeanOperationInfo findOperation(MBeanOperationInfo[] ops, String name) {
for (MBeanOperationInfo op : ops) {
Assert.assertNotNull(op.getName());
if (op.getName().equals(name)) {
return assertCast(OpenMBeanOperationInfo.class, op);
}
}
Assert.fail("No op called " + name);
return null;
}
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);
}
}