当前位置: 首页>>代码示例>>Java>>正文


Java MBeanServer.getMBeanInfo方法代码示例

本文整理汇总了Java中javax.management.MBeanServer.getMBeanInfo方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServer.getMBeanInfo方法的具体用法?Java MBeanServer.getMBeanInfo怎么用?Java MBeanServer.getMBeanInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.management.MBeanServer的用法示例。


在下文中一共展示了MBeanServer.getMBeanInfo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_simple

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void test_simple() {
    MBeanServer mBeanServer = exporter.getServer();

    try {
        ObjectName objectName = new ObjectName("bean:name=otterControllor");
        MBeanInfo nodeInfo = mBeanServer.getMBeanInfo(objectName);
        System.out.println(nodeInfo);
        Object result = mBeanServer.getAttribute(objectName, "HeapMemoryUsage");
        System.out.println(result);

        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/mbean");
        Map environment = null;

        JMXConnector cntor = JMXConnectorFactory.connect(address, environment);
        MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
        String domain = mbsc.getDefaultDomain();
        System.out.println(domain);

        result = mbsc.getAttribute(objectName, "HeapMemoryUsage");
        System.out.println(result);
    } catch (Exception e) {
        want.fail(e.getMessage());
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:26,代码来源:JmxLoaderIntegration.java

示例2: test

import javax.management.MBeanServer; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ImmutableNotificationInfoTest.java

示例3: registerJmxMBean

import javax.management.MBeanServer; //导入方法依赖的package包/类
private void registerJmxMBean() {
  try {
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName(settings.getJmxMBeanName());
    mBeanServer.registerMBean(new JmxConfigRegistry(this), objectName);
    MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName);
    LOGGER.info("Registered JMX MBean: {}", mBeanInfo);
  } catch (Exception e) {
    LOGGER.warn("Failed to register JMX MBean '{}', cause: {}", settings.getJmxMBeanName(), e);
  }
}
 
开发者ID:scalecube,项目名称:config,代码行数:12,代码来源:ConfigRegistryImpl.java

示例4: run

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Override
public void run() {
  try {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    // Metrics that belong to "FSNamesystem", these are metrics that
    // come from hadoop metrics framework for the class FSNamesystem.
    ObjectName mxbeanNamefsn = new ObjectName(
        "Hadoop:service=NameNode,name=FSNamesystem");

    // Metrics that belong to "FSNamesystemState".
    // These are metrics that FSNamesystem registers directly with MBeanServer.
    ObjectName mxbeanNameFsns = new ObjectName(
        "Hadoop:service=NameNode,name=FSNamesystemState");

    // Metrics that belong to "NameNodeInfo".
    // These are metrics that FSNamesystem registers directly with MBeanServer.
    ObjectName mxbeanNameNni = new ObjectName(
        "Hadoop:service=NameNode,name=NameNodeInfo");

    final Set<ObjectName> mbeans = new HashSet<ObjectName>();
    mbeans.add(mxbeanNamefsn);
    mbeans.add(mxbeanNameFsns);
    mbeans.add(mxbeanNameNni);

    for(ObjectName mbean : mbeans) {
      MBeanInfo attributes = mbs.getMBeanInfo(mbean);
      for (MBeanAttributeInfo attributeInfo : attributes.getAttributes()) {
        mbs.getAttribute(mbean, attributeInfo.getName());
      }
    }

    succeeded = true;
  } catch (Exception e) {
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:37,代码来源:TestFSNamesystemMBean.java

示例5: checkMBean

import javax.management.MBeanServer; //导入方法依赖的package包/类
private static void checkMBean(MBeanServer mbs, String mbeanName)
        throws Exception {
    try {
        ObjectName objName = new ObjectName(mbeanName);
        // We could call mbs.isRegistered(objName) here.
        // Calling getMBeanInfo will throw exception if not found.
        mbs.getMBeanInfo(objName);
    } catch (Exception e) {
        throw e;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:PlatformMBeanServerTest.java

示例6: testMXBean

import javax.management.MBeanServer; //导入方法依赖的package包/类
private static void testMXBean(MBeanServer mbs, ObjectName on)
        throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    int nattrs = attrs.length;
    if (mbi.getAttributes().length != 1)
        failure("wrong number of attributes: " + attrs);
    else {
        MBeanAttributeInfo mbai = attrs[0];
        if (mbai.getName().equals("Ints")
            && mbai.isReadable() && !mbai.isWritable()
            && mbai.getDescriptor().getFieldValue("openType")
                .equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
            && attrs[0].getType().equals("[I"))
            success("MBeanAttributeInfo");
        else
            failure("MBeanAttributeInfo: " + mbai);
    }

    int[] ints = (int[]) mbs.getAttribute(on, "Ints");
    if (equal(ints, new int[] {1, 2, 3}, null))
        success("getAttribute");
    else
        failure("getAttribute: " + Arrays.toString(ints));

    ExplicitMXBean proxy =
        JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
    int[] pints = proxy.getInts();
    if (equal(pints, new int[] {1, 2, 3}, null))
        success("getAttribute through proxy");
    else
        failure("getAttribute through proxy: " + Arrays.toString(pints));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:MXBeanTest.java

示例7: check

import javax.management.MBeanServer; //导入方法依赖的package包/类
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());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:AnnotationTest.java

示例8: readBeanInfo

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void readBeanInfo() throws Exception {
    ObjectName name;

    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());

    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);
    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);

    MBeanAttributeInfo printCompilation = (MBeanAttributeInfo) findAttributeInfo("PrintCompilation", info);
    assertNotNull("PrintCompilation found", printCompilation);
    assertEquals("true/false", Boolean.class.getName(), printCompilation.getType());

    Attribute printOn = new Attribute(printCompilation.getName(), Boolean.TRUE);

    Object before = server.getAttribute(name, printCompilation.getName());
    server.setAttribute(name, printOn);
    Object after = server.getAttribute(name, printCompilation.getName());

    assertNull("Default value was not set", before);
    assertEquals("Changed to on", Boolean.TRUE, after);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:HotSpotGraalMBeanTest.java

示例9: main

import javax.management.MBeanServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    TestMXBean testImpl = (TestMXBean) Proxy.newProxyInstance(
            TestMXBean.class.getClassLoader(), new Class<?>[] {TestMXBean.class}, nullIH);
    Object mxbean = new StandardMBean(testImpl, TestMXBean.class, true);
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    mbs.registerMBean(mxbean, name);
    MBeanInfo mbi = mbs.getMBeanInfo(name);
    MBeanAttributeInfo[] mbais = mbi.getAttributes();
    boolean sawTabular = false;
    for (MBeanAttributeInfo mbai : mbais) {
        String attrName = mbai.getName();
        String attrTypeName = (String) mbai.getDescriptor().getFieldValue("originalType");
        String fieldName = attrName + "Name";
        Field nameField = TestMXBean.class.getField(fieldName);
        String expectedTypeName = (String) nameField.get(null);

        if (expectedTypeName.equals(attrTypeName)) {
            System.out.println("OK: " + attrName + ": " + attrTypeName);
        } else {
            fail("For attribute " + attrName + " expected type name \"" +
                    expectedTypeName + "\", found type name \"" + attrTypeName +
                    "\"");
        }

        if (mbai.getType().equals(TabularData.class.getName())) {
            sawTabular = true;
            TabularType tt = (TabularType) mbai.getDescriptor().getFieldValue("openType");
            if (tt.getTypeName().equals(attrTypeName)) {
                System.out.println("OK: TabularType name for " + attrName);
            } else {
                fail("For attribute " + attrName + " expected TabularType " +
                        "name \"" + attrTypeName + "\", found \"" +
                        tt.getTypeName());
            }
        }
    }

    if (!sawTabular)
        fail("Test bug: did not test TabularType name");

    if (failure == null)
        System.out.println("TEST PASSED");
    else
        throw new Exception("TEST FAILED: " + failure);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:47,代码来源:TypeNameTest.java

示例10: test

import javax.management.MBeanServer; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:69,代码来源:TooManyFooTest.java

示例11: dumpOperation

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void dumpOperation() throws Exception {
    Field field = null;
    try {
        field = stopMBeanServer();
    } catch (Exception ex) {
        if (ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
            // skip on JDK9
            return;
        }
    }
    assertNull("The platformMBeanServer isn't initialized now", field.get(null));

    ObjectName name;

    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());

    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);

    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);

    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);

    final MBeanOperationInfo[] arr = info.getOperations();
    assertEquals("Currently three overloads", 3, arr.length);
    MBeanOperationInfo dumpOp = null;
    for (int i = 0; i < arr.length; i++) {
        assertEquals("dumpMethod", arr[i].getName());
        if (arr[i].getSignature().length == 3) {
            dumpOp = arr[i];
        }
    }
    assertNotNull("three args variant found", dumpOp);

    server.invoke(name, "dumpMethod", new Object[]{
                    "java.util.Arrays", "asList", ":3"
    }, null);

    MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);
    Attribute dumpTo1 = new Attribute(dump.getName(), "");
    server.setAttribute(name, dumpTo1);
    Object after = server.getAttribute(name, dump.getName());
    assertEquals("", after);

    OptionValues empty = new OptionValues(EconomicMap.create());
    OptionValues unsetDump = realBean.optionsFor(empty, null);
    final MetaAccessProvider metaAccess = jdk.vm.ci.runtime.JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
    ResolvedJavaMethod method = metaAccess.lookupJavaMethod(Arrays.class.getMethod("asList", Object[].class));
    final OptionValues forMethod = realBean.optionsFor(unsetDump, method);
    assertNotSame(unsetDump, forMethod);
    Object nothing = unsetDump.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", nothing);

    Object specialValue = forMethod.getMap().get(DebugOptions.Dump);
    assertEquals(":3", specialValue);

    OptionValues normalMethod = realBean.optionsFor(unsetDump, null);
    Object noSpecialValue = normalMethod.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", noSpecialValue);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:HotSpotGraalMBeanTest.java

示例12: optionsAreCached

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void optionsAreCached() throws Exception {
    ObjectName name;

    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());

    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);

    OptionValues original = new OptionValues(EconomicMap.create());

    assertSame(original, realBean.optionsFor(original, null));

    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);

    MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);

    Attribute dumpTo1 = new Attribute(dump.getName(), 1);

    server.setAttribute(name, dumpTo1);
    Object after = server.getAttribute(name, dump.getName());
    assertEquals(1, after);

    final OptionValues modified1 = realBean.optionsFor(original, null);
    assertNotSame(original, modified1);
    final OptionValues modified2 = realBean.optionsFor(original, null);
    assertSame("Options are cached", modified1, modified2);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:HotSpotGraalMBeanTest.java


注:本文中的javax.management.MBeanServer.getMBeanInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。