Java Code Examples for javax.management.MBeanOperationInfo#getName()

The following examples show how to use javax.management.MBeanOperationInfo#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteStandardMXBean.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: ReflectionMBeanOperation.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example 3
Source File: OperationKey.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: TooManyFooTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 5
Source File: TooManyFooTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 6
Source File: TooManyFooTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 7
Source File: TooManyFooTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 8
Source File: TooManyFooTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 9
Source File: TooManyFooTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 10
Source File: TooManyFooTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 11
Source File: TooManyFooTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 12
Source File: TooManyFooTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 13
Source File: TooManyFooTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 14
Source File: TooManyFooTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 15
Source File: MBeanInfoRenderer.java    From text-ui with GNU General Public License v3.0 4 votes vote down vote up
@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);
}
 
Example 16
Source File: TooManyFooTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}
 
Example 17
Source File: TooManyFooTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}