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);
}
}
java类javax.management.openmbean.OpenMBeanOperationInfo的实例源码
TooManyFooTest.java 文件源码
项目:jdk7-jdk
阅读 24
收藏 0
点赞 0
评论 0
TooManyFooTest.java 文件源码
项目:openjdk-source-code-learn
阅读 22
收藏 0
点赞 0
评论 0
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);
}
}
TooManyFooTest.java 文件源码
项目:OLD-OpenJDK8
阅读 22
收藏 0
点赞 0
评论 0
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);
}
}
BeanImpl.java 文件源码
项目:JamVM-PH
阅读 21
收藏 0
点赞 0
评论 0
protected void cacheMBeanInfo(MBeanInfo info)
{
if (info == null)
return;
try
{
MBeanAttributeInfo[] oldA = info.getAttributes();
OpenMBeanAttributeInfo[] attribs =
new OpenMBeanAttributeInfoSupport[oldA.length];
for (int a = 0; a < oldA.length; ++a)
{
OpenMBeanParameterInfo param = Translator.translate(oldA[a].getType());
if (param.getMinValue() == null)
{
Object[] lv;
if (param.getLegalValues() == null)
lv = null;
else
lv = param.getLegalValues().toArray();
attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
oldA[a].getDescription(),
((OpenType<Object>)
param.getOpenType()),
oldA[a].isReadable(),
oldA[a].isWritable(),
oldA[a].isIs(),
param.getDefaultValue(),
lv);
}
else
attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
oldA[a].getDescription(),
((OpenType<Object>)
param.getOpenType()),
oldA[a].isReadable(),
oldA[a].isWritable(),
oldA[a].isIs(),
param.getDefaultValue(),
((Comparable<Object>)
param.getMinValue()),
((Comparable<Object>)
param.getMaxValue()));
}
MBeanConstructorInfo[] oldC = info.getConstructors();
OpenMBeanConstructorInfo[] cons = new OpenMBeanConstructorInfoSupport[oldC.length];
for (int a = 0; a < oldC.length; ++a)
cons[a] =
new OpenMBeanConstructorInfoSupport(oldC[a].getName(),
oldC[a].getDescription(),
translateSignature(oldC[a].getSignature()));
MBeanOperationInfo[] oldO = info.getOperations();
OpenMBeanOperationInfo[] ops = new OpenMBeanOperationInfoSupport[oldO.length];
for (int a = 0; a < oldO.length; ++a)
ops[a] =
new OpenMBeanOperationInfoSupport(oldO[a].getName(),
oldO[a].getDescription(),
translateSignature(oldO[a].getSignature()),
Translator.translate(oldO[a].getReturnType()).getOpenType(),
oldO[a].getImpact());
openInfo = new OpenMBeanInfoSupport(info.getClassName(), info.getDescription(),
attribs, cons, ops, info.getNotifications());
}
catch (OpenDataException e)
{
throw (InternalError) (new InternalError("A problem occurred creating the open type " +
"descriptors.").initCause(e));
}
}
ModelControllerMBeanTestCase.java 文件源码
项目:wildfly-core
阅读 18
收藏 0
点赞 0
评论 0
@Test
public void testAddMethodSingleFixedChild() throws Exception {
final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test");
final ObjectName childObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,single=only");
MBeanServerConnection connection = setupAndGetConnection(new MBeanInfoAdditionalInitialization(ProcessType.STANDALONE_SERVER, new SubystemWithSingleFixedChildExtension()));
Set<ObjectName> names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null);
Assert.assertEquals(1, names.size());
Assert.assertTrue(names.contains(testObjectName));
MBeanInfo subsystemInfo = connection.getMBeanInfo(testObjectName);
Assert.assertEquals(0, subsystemInfo.getAttributes().length);
Assert.assertEquals(1, subsystemInfo.getOperations().length);
OpenMBeanOperationInfo op = findOperation(subsystemInfo.getOperations(), "addSingleOnly");
Assert.assertEquals("add", op.getDescription());
Assert.assertEquals(1, op.getSignature().length);
Assert.assertEquals(Integer.class.getName(), op.getSignature()[0].getType());
connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()});
names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null);
Assert.assertEquals(2, names.size());
Assert.assertTrue(names.contains(testObjectName));
Assert.assertTrue(names.contains(childObjectName));
subsystemInfo = connection.getMBeanInfo(testObjectName);
Assert.assertEquals(0, subsystemInfo.getAttributes().length);
Assert.assertEquals(1, subsystemInfo.getOperations().length);
op = findOperation(subsystemInfo.getOperations(), "addSingleOnly");
Assert.assertEquals("add", op.getDescription());
Assert.assertEquals(1, op.getSignature().length);
Assert.assertEquals(Integer.class.getName(), op.getSignature()[0].getType());
MBeanInfo childInfo = connection.getMBeanInfo(childObjectName);
Assert.assertEquals(1, childInfo.getAttributes().length);
Assert.assertEquals(Integer.class.getName(), childInfo.getAttributes()[0].getType());
Assert.assertEquals(1, childInfo.getOperations().length);
op = findOperation(childInfo.getOperations(), REMOVE);
Assert.assertEquals("remove", op.getDescription());
Assert.assertEquals(0, op.getSignature().length);
Assert.assertEquals(123, connection.getAttribute(childObjectName, "attr"));
try {
connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()});
Assert.fail("Should not have been able to register a duplicate resource");
} catch (Exception expected) {
//expected
}
connection.invoke(childObjectName, REMOVE, new Object[]{}, new String[]{});
names = connection.queryNames(createObjectName(LEGACY_DOMAIN + ":subsystem=test,*"), null);
Assert.assertEquals(1, names.size());
Assert.assertTrue(names.contains(testObjectName));
}
TooManyFooTest.java 文件源码
项目:JAVA_UNIT
阅读 24
收藏 0
点赞 0
评论 0
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);
}
}
TooManyFooTest.java 文件源码
项目:openjdk-jdk7u-jdk
阅读 25
收藏 0
点赞 0
评论 0
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);
}
}
BeanImpl.java 文件源码
项目:classpath
阅读 23
收藏 0
点赞 0
评论 0
protected void cacheMBeanInfo(MBeanInfo info)
{
if (info == null)
return;
try
{
MBeanAttributeInfo[] oldA = info.getAttributes();
OpenMBeanAttributeInfo[] attribs =
new OpenMBeanAttributeInfoSupport[oldA.length];
for (int a = 0; a < oldA.length; ++a)
{
OpenMBeanParameterInfo param = Translator.translate(oldA[a].getType());
if (param.getMinValue() == null)
{
Object[] lv;
if (param.getLegalValues() == null)
lv = null;
else
lv = param.getLegalValues().toArray();
attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
oldA[a].getDescription(),
((OpenType<Object>)
param.getOpenType()),
oldA[a].isReadable(),
oldA[a].isWritable(),
oldA[a].isIs(),
param.getDefaultValue(),
lv);
}
else
attribs[a] = new OpenMBeanAttributeInfoSupport(oldA[a].getName(),
oldA[a].getDescription(),
((OpenType<Object>)
param.getOpenType()),
oldA[a].isReadable(),
oldA[a].isWritable(),
oldA[a].isIs(),
param.getDefaultValue(),
((Comparable<Object>)
param.getMinValue()),
((Comparable<Object>)
param.getMaxValue()));
}
MBeanConstructorInfo[] oldC = info.getConstructors();
OpenMBeanConstructorInfo[] cons = new OpenMBeanConstructorInfoSupport[oldC.length];
for (int a = 0; a < oldC.length; ++a)
cons[a] =
new OpenMBeanConstructorInfoSupport(oldC[a].getName(),
oldC[a].getDescription(),
translateSignature(oldC[a].getSignature()));
MBeanOperationInfo[] oldO = info.getOperations();
OpenMBeanOperationInfo[] ops = new OpenMBeanOperationInfoSupport[oldO.length];
for (int a = 0; a < oldO.length; ++a)
ops[a] =
new OpenMBeanOperationInfoSupport(oldO[a].getName(),
oldO[a].getDescription(),
translateSignature(oldO[a].getSignature()),
Translator.translate(oldO[a].getReturnType()).getOpenType(),
oldO[a].getImpact());
openInfo = new OpenMBeanInfoSupport(info.getClassName(), info.getDescription(),
attribs, cons, ops, info.getNotifications());
}
catch (OpenDataException e)
{
throw (InternalError) (new InternalError("A problem occurred creating the open type " +
"descriptors.").initCause(e));
}
}
TooManyFooTest.java 文件源码
项目:openjdk-icedtea7
阅读 23
收藏 0
点赞 0
评论 0
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);
}
}