Java Code Examples for javax.management.MBeanAttributeInfo.getName()

The following are Jave code examples for showing how to use getName() of the javax.management.MBeanAttributeInfo class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: eZooKeeper   File: MBean.java   Source Code and License Vote up 6 votes
/**
 * TODO: Comment.
 * 
 */
private void initAttributeCollections() {

    MBeanAttributeInfo[] attributeInfos = _Info.getAttributes();
    int size = 0;
    if (attributeInfos != null) {
        size = attributeInfos.length;
    }
    _AttributeNames = new TreeSet<String>();
    _AttributeInfoMap = new HashMap<String, MBeanAttributeInfo>(size);

    if (size == 0) {
        return;
    }

    for (MBeanAttributeInfo attributeInfo : attributeInfos) {
        String attributeName = attributeInfo.getName();

        _AttributeNames.add(attributeName);
        _AttributeInfoMap.put(attributeName, attributeInfo);
    }

}
 
Example 2
Project: truevfs   File: JmxBufferView.java   Source Code and License Vote up 6 votes
@Override
protected String getDescription(final MBeanAttributeInfo info) {
    switch (info.getName()) {
    case "Name":
        return "The name of this buffer.";
    case "SizeOfData":
        return "The data size of this buffer.";
    case "SizeOfStorage":
        return "The storage size of this buffer.";
    case "TimeCreatedDate":
        return "The time this buffer has been created.";
    case "TimeCreatedMillis":
        return "The time this buffer has been created in milliseconds.";
    case "TimeReadDate":
        return "The last time this buffer has been read or accessed.";
    case "TimeReadMillis":
        return "The last time this buffer has been read or accessed in milliseconds.";
    case "TimeWrittenDate":
        return "The last time this buffer has been written.";
    case "TimeWrittenMillis":
        return "The last time this buffer has been written in milliseconds.";
    default:
        return null;
    }
}
 
Example 3
Project: openjdk-jdk10   File: OldMBeanServerTest.java   Source Code and License Vote up 6 votes
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 4
Project: Pogamut3   File: AttributeToPropertyAdapter.java   Source Code and License Vote up 5 votes
public AttributeToPropertyAdapter(MBeanAttributeInfo info, DynamicMBean folderMBean) {
    super(info.getName());
    this.folderMBean = folderMBean;
    this.info = info;

    // find the attr info
    /*for (MBeanAttributeInfo nfo : folderMBean.getAttributeInfos()) {
    if (info.getName().equals(attributeName)) {
    this.info = nfo;
    break;
    }
    }
     */
}
 
Example 5
Project: truevfs   File: JmxManagerView.java   Source Code and License Vote up 5 votes
@Override
protected String getDescription(final MBeanAttributeInfo info) {
    switch (info.getName()) {
    case "FileSystemsMounted":
        return "The number of file systems which have been mounted.";
    case "FileSystemsTotal":
        return "The total number of file systems.";
    case "TopLevelArchiveFileSystemsMounted":
        return "The number of top level archive file systems which have been mounted.";
    case "TopLevelArchiveFileSystemsTotal":
        return "The total number of top level archive file systems.";
    default:
        return null;
    }
}
 
Example 6
Project: truevfs   File: JmxModelView.java   Source Code and License Vote up 5 votes
@Override
protected String getDescription(final MBeanAttributeInfo info) {
    switch (info.getName()) {
    case "Mounted":
        return "Whether or not this file system is mounted.";
    case "MountPoint":
        return "The mount point URI of this file system.";
    case "MountPointOfParent":
        return "The mount point URI of the parent file system.";
    case "SizeOfData":
        return "The data size of this file system.";
    case "SizeOfStorage":
        return "The storage size of this file system.";
    case "TimeCreatedDate":
        return "The time this file system has been created.";
    case "TimeCreatedMillis":
        return "The time this file system has been created in milliseconds.";
    case "TimeReadDate":
        return "The last time this file system has been read or accessed.";
    case "TimeReadMillis":
        return "The last time this file system has been read or accessed in milliseconds.";
    case "TimeWrittenDate":
        return "The last time this file system has been written.";
    case "TimeWrittenMillis":
        return "The last time this file system has been written in milliseconds.";
    default:
        return null;
    }
}
 
Example 7
Project: jdk8u-jdk   File: OldMBeanServerTest.java   Source Code and License Vote up 5 votes
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 8
Project: openjdk-jdk10   File: HotSpotGraalMBeanTest.java   Source Code and License Vote up 5 votes
@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);
}
 
Example 9
Project: jdk8u-jdk   File: TypeNameTest.java   Source Code and License Vote up 4 votes
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);
}
 
Example 10
Project: openjdk-jdk10   File: HotSpotGraalMBeanTest.java   Source Code and License Vote up 4 votes
@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);
}
 
Example 11
Project: openjdk-jdk10   File: TypeNameTest.java   Source Code and License Vote up 4 votes
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);
}
 
Example 12
Project: openjdk-jdk10   File: HotSpotGraalMBeanTest.java   Source Code and License Vote up 3 votes
@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);

}