Java Code Examples for javax.management.openmbean.CompositeData#get()

The following examples show how to use javax.management.openmbean.CompositeData#get() . 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: GenericArrayTypeTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static MonitorInfo from(CompositeData cd) {
    try {
        CompositeData stecd = (CompositeData) cd.get("lockedStackFrame");
        StackTraceElement ste = new StackTraceElement(
                (String) stecd.get("className"),
                (String) stecd.get("methodName"),
                (String) stecd.get("fileName"),
                (Integer) stecd.get("lineNumber"));
        return new MonitorInfo(
                (String) cd.get("className"),
                (Integer) cd.get("identityHashCode"),
                (Integer) cd.get("lockedStackDepth"),
                ste);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: DefaultMXBeanMappingFactory.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
Object fromCompositeData(CompositeData cd,
                         String[] itemNames,
                         MXBeanMapping[] converters)
        throws InvalidObjectException {
    Object o;
    try {
        final Class<?> targetClass = getTargetClass();
        ReflectUtil.checkPackageAccess(targetClass);
        o = targetClass.newInstance();
        for (int i = 0; i < itemNames.length; i++) {
            if (cd.containsKey(itemNames[i])) {
                Object openItem = cd.get(itemNames[i]);
                Object javaItem =
                    converters[i].fromOpenValue(openItem);
                MethodUtil.invoke(setters[i], o, new Object[] {javaItem});
            }
        }
    } catch (Exception e) {
        throw invalidObjectException(e);
    }
    return o;
}
 
Example 3
Source File: Client.java    From vjtools with Apache License 2.0 6 votes vote down vote up
protected static StringBuffer recurseCompositeData(StringBuffer buffer, String indent, String name,
		CompositeData data) {
	indent = addNameToBuffer(buffer, indent, name);
	for (Iterator i = data.getCompositeType().keySet().iterator(); i.hasNext();) {
		String key = (String) i.next();
		Object o = data.get(key);
		if (o instanceof CompositeData) {
			recurseCompositeData(buffer, indent + " ", key, (CompositeData) o);
		} else if (o instanceof TabularData) {
			recurseTabularData(buffer, indent, key, (TabularData) o);
		} else {
			buffer.append(indent);
			buffer.append(key);
			buffer.append(": ");
			buffer.append(o);
			buffer.append("\n");
		}
	}
	return buffer;
}
 
Example 4
Source File: DefaultMXBeanMappingFactory.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
Object fromCompositeData(CompositeData cd,
                         String[] itemNames,
                         MXBeanMapping[] converters)
        throws InvalidObjectException {
    Object o;
    try {
        final Class<?> targetClass = getTargetClass();
        ReflectUtil.checkPackageAccess(targetClass);
        o = targetClass.newInstance();
        for (int i = 0; i < itemNames.length; i++) {
            if (cd.containsKey(itemNames[i])) {
                Object openItem = cd.get(itemNames[i]);
                Object javaItem =
                    converters[i].fromOpenValue(openItem);
                MethodUtil.invoke(setters[i], o, new Object[] {javaItem});
            }
        }
    } catch (Exception e) {
        throw invalidObjectException(e);
    }
    return o;
}
 
Example 5
Source File: RecordingInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private RecordingInfo(CompositeData cd) {
    id = (int) cd.get("id");
    name = (String) cd.get("name");
    state = (String) cd.get("state");
    dumpOnExit = (boolean) cd.get("dumpOnExit");
    size = (long) cd.get("size");
    disk = (boolean) cd.get("disk");
    maxAge = (Long) cd.get("maxAge");
    maxSize = (Long) cd.get("maxSize");
    startTime = (Long) cd.get("startTime");
    stopTime = (Long) cd.get("stopTime");
    destination = (String) cd.get("destination");
    durationInSeconds = (long) cd.get("duration");
    settings = new LinkedHashMap<>();
    Object map = cd.get("settings");
    if (map instanceof TabularData) {
        TabularData td = (TabularData) map;
        List<String> keyNames = td.getTabularType().getIndexNames();
        int size = keyNames.size();
        for (Object keys : td.keySet()) {
            Object[] keyValues = ((List<?>) keys).toArray();
            for (int i = 0; i < size; i++) {
                String key = keyNames.get(i);
                Object value = keyValues[i];
                if (value instanceof String) {
                    settings.put(key, (String) value);
                }
            }
        }
    }
}
 
Example 6
Source File: MonitorInfoCompositeData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static StackTraceElement getLockedStackFrame(CompositeData cd) {
    CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME);
    if (ste != null) {
        return StackTraceElementCompositeData.from(ste);
    } else {
        return null;
    }
}
 
Example 7
Source File: GcInfoCompositeData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static Map<String, MemoryUsage>
        getMemoryUsageAfterGc(CompositeData cd) {
    try {
        TabularData td = (TabularData) cd.get(MEMORY_USAGE_AFTER_GC);
        //return (Map<String,MemoryUsage>)
        return cast(memoryUsageMapType.toJavaTypeData(td));
    } catch (InvalidObjectException | OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 8
Source File: GcInfoCompositeData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static Map<String, MemoryUsage>
        getMemoryUsageAfterGc(CompositeData cd) {
    try {
        TabularData td = (TabularData) cd.get(MEMORY_USAGE_AFTER_GC);
        //return (Map<String,MemoryUsage>)
        return cast(memoryUsageMapType.toJavaTypeData(td));
    } catch (InvalidObjectException | OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 9
Source File: SettingDescriptorInfo.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private SettingDescriptorInfo(CompositeData cd) {
    this.name = (String) cd.get("name");
    this.label = (String) cd.get("label");
    this.description = (String) cd.get("description");
    this.typeName = (String) cd.get("typeName");
    this.defaultValue = (String) cd.get("defaultValue");
    this.contentType = (String) cd.get("contentType");
}
 
Example 10
Source File: MonitorInfoCompositeData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static StackTraceElement getLockedStackFrame(CompositeData cd) {
    CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME);
    if (ste != null) {
        return StackTraceElementCompositeData.from(ste);
    } else {
        return null;
    }
}
 
Example 11
Source File: GcInfoCompositeData.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static Map<String, MemoryUsage>
        getMemoryUsageBeforeGc(CompositeData cd) {
    try {
        TabularData td = (TabularData) cd.get(MEMORY_USAGE_BEFORE_GC);
        return cast(memoryUsageMapType.toJavaTypeData(td));
    } catch (InvalidObjectException | OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 12
Source File: ConfigurationInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private ConfigurationInfo(CompositeData cd) {
    this.settings = createMap(cd.get("settings"));
    this.name = (String) cd.get("name");
    this.label = (String) cd.get("label");
    this.description = (String) cd.get("description");
    this.provider = (String) cd.get("provider");
    this.contents = (String) cd.get("contents");
}
 
Example 13
Source File: GcInfoCompositeData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Map<String, MemoryUsage>
        getMemoryUsageAfterGc(CompositeData cd) {
    try {
        TabularData td = (TabularData) cd.get(MEMORY_USAGE_AFTER_GC);
        //return (Map<String,MemoryUsage>)
        return cast(memoryUsageMapType.toJavaTypeData(td));
    } catch (InvalidObjectException | OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 14
Source File: Client.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/**
 * Allows for reconstruction via CompositeData.
 *
 * @param cd
 *            composite data
 * @return Client class instance
 */
public static Client from(CompositeData cd) {
    Client instance = null;
    if (cd.containsKey("id")) {
        String id = (String) cd.get("id");
        instance = new Client(id, (Long) cd.get("creationTime"), null);
        instance.setAttribute(PERMISSIONS, cd.get(PERMISSIONS));
    }
    if (cd.containsKey("attributes")) {
        AttributeStore attrs = (AttributeStore) cd.get("attributes");
        instance.setAttributes(attrs);
    }
    return instance;
}
 
Example 15
Source File: PropertyNamesTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName pointName = new ObjectName("a:type=Point");
    PointMXBean pointmx = new PointImpl();
    mbs.registerMBean(pointmx, pointName);
    Point point = new Point(1, 2);
    PointMXBean pointproxy =
        JMX.newMXBeanProxy(mbs, pointName, PointMXBean.class);
    Point point1 = pointproxy.identity(point);
    if (point1.getX() != point.getX() || point1.getY() != point.getY())
        throw new Exception("Point doesn't match");
    System.out.println("Point test passed");

    ObjectName evolveName = new ObjectName("a:type=Evolve");
    EvolveMXBean evolvemx = new EvolveImpl();
    mbs.registerMBean(evolvemx, evolveName);
    Evolve evolve =
        new Evolve(59, "tralala", Collections.singletonList("tiddly"));
    EvolveMXBean evolveProxy =
        JMX.newMXBeanProxy(mbs, evolveName, EvolveMXBean.class);
    Evolve evolve1 = evolveProxy.identity(evolve);
    if (evolve1.getOldInt() != evolve.getOldInt()
            || !evolve1.getNewString().equals(evolve.getNewString())
            || !evolve1.getNewerList().equals(evolve.getNewerList()))
        throw new Exception("Evolve doesn't match");
    System.out.println("Evolve test passed");

    ObjectName evolvedName = new ObjectName("a:type=Evolved");
    EvolveMXBean evolvedmx = new EvolveImpl();
    mbs.registerMBean(evolvedmx, evolvedName);
    CompositeType evolvedType =
        new CompositeType("Evolved", "descr", new String[] {"oldInt"},
                          new String[] {"oldInt descr"},
                          new OpenType[] {SimpleType.INTEGER});
    CompositeData evolvedData =
        new CompositeDataSupport(evolvedType, new String[] {"oldInt"},
                                 new Object[] {5});
    CompositeData evolved1 = (CompositeData)
        mbs.invoke(evolvedName, "identity", new Object[] {evolvedData},
                   new String[] {CompositeData.class.getName()});
    if ((Integer) evolved1.get("oldInt") != 5
            || !evolved1.get("newString").equals("defaultString")
            || ((String[]) evolved1.get("newerList")).length != 0)
        throw new Exception("Evolved doesn't match: " + evolved1);
    System.out.println("Evolved test passed");
}
 
Example 16
Source File: ThreadInfoCompositeData.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/** Validate if the input CompositeData has the expected
 * CompositeType (i.e. contain all attributes with expected
 * names and types).
 */
public static void validateCompositeData(CompositeData cd) {
    if (cd == null) {
        throw new NullPointerException("Null CompositeData");
    }

    CompositeType type = cd.getCompositeType();
    boolean currentVersion = true;
    if (!isTypeMatched(threadInfoCompositeType, type)) {
        currentVersion = false;
        // check if cd is an older version
        if (!isTypeMatched(threadInfoV5CompositeType, type)) {
            throw new IllegalArgumentException(
                "Unexpected composite type for ThreadInfo");
        }
    }

    CompositeData[] stackTraceData =
        (CompositeData[]) cd.get(STACK_TRACE);
    if (stackTraceData == null) {
        throw new IllegalArgumentException(
            "StackTraceElement[] is missing");
    }
    if (stackTraceData.length > 0) {
        StackTraceElementCompositeData.validateCompositeData(stackTraceData[0]);
    }

    // validate v6 attributes
    if (currentVersion) {
        CompositeData li = (CompositeData) cd.get(LOCK_INFO);
        if (li != null) {
            if (!isTypeMatched(lockInfoCompositeType,
                               li.getCompositeType())) {
                throw new IllegalArgumentException(
                    "Unexpected composite type for \"" +
                    LOCK_INFO + "\" attribute.");
            }
        }

        CompositeData[] lms = (CompositeData[]) cd.get(LOCKED_MONITORS);
        if (lms == null) {
            throw new IllegalArgumentException("MonitorInfo[] is null");
        }
        if (lms.length > 0) {
            MonitorInfoCompositeData.validateCompositeData(lms[0]);
        }

        CompositeData[] lsyncs = (CompositeData[]) cd.get(LOCKED_SYNCS);
        if (lsyncs == null) {
            throw new IllegalArgumentException("LockInfo[] is null");
        }
        if (lsyncs.length > 0) {
            if (!isTypeMatched(lockInfoCompositeType,
                               lsyncs[0].getCompositeType())) {
                throw new IllegalArgumentException(
                    "Unexpected composite type for \"" +
                    LOCKED_SYNCS + "\" attribute.");
            }
        }

    }
}
 
Example 17
Source File: LazyCompositeData.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static boolean getBoolean(CompositeData cd, String itemName) {
    if (cd == null)
        throw new IllegalArgumentException("Null CompositeData");

    return ((Boolean) cd.get(itemName));
}
 
Example 18
Source File: ThreadInfoCompositeData.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/** Validate if the input CompositeData has the expected
 * CompositeType (i.e. contain all attributes with expected
 * names and types).
 */
public static void validateCompositeData(CompositeData cd) {
    if (cd == null) {
        throw new NullPointerException("Null CompositeData");
    }

    CompositeType type = cd.getCompositeType();
    boolean currentVersion = true;
    if (!isTypeMatched(threadInfoCompositeType, type)) {
        currentVersion = false;
        // check if cd is an older version
        if (!isTypeMatched(threadInfoV5CompositeType, type)) {
            throw new IllegalArgumentException(
                "Unexpected composite type for ThreadInfo");
        }
    }

    CompositeData[] stackTraceData =
        (CompositeData[]) cd.get(STACK_TRACE);
    if (stackTraceData == null) {
        throw new IllegalArgumentException(
            "StackTraceElement[] is missing");
    }
    if (stackTraceData.length > 0) {
        StackTraceElementCompositeData.validateCompositeData(stackTraceData[0]);
    }

    // validate v6 attributes
    if (currentVersion) {
        CompositeData li = (CompositeData) cd.get(LOCK_INFO);
        if (li != null) {
            if (!isTypeMatched(lockInfoCompositeType,
                               li.getCompositeType())) {
                throw new IllegalArgumentException(
                    "Unexpected composite type for \"" +
                    LOCK_INFO + "\" attribute.");
            }
        }

        CompositeData[] lms = (CompositeData[]) cd.get(LOCKED_MONITORS);
        if (lms == null) {
            throw new IllegalArgumentException("MonitorInfo[] is null");
        }
        if (lms.length > 0) {
            MonitorInfoCompositeData.validateCompositeData(lms[0]);
        }

        CompositeData[] lsyncs = (CompositeData[]) cd.get(LOCKED_SYNCS);
        if (lsyncs == null) {
            throw new IllegalArgumentException("LockInfo[] is null");
        }
        if (lsyncs.length > 0) {
            if (!isTypeMatched(lockInfoCompositeType,
                               lsyncs[0].getCompositeType())) {
                throw new IllegalArgumentException(
                    "Unexpected composite type for \"" +
                    LOCKED_SYNCS + "\" attribute.");
            }
        }

    }
}
 
Example 19
Source File: MerlinMXBean.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static ExoticCompositeData from(CompositeData cd) {
    String whatsit = (String) cd.get("whatsit");
    if (!whatsit.startsWith("!"))
        throw new IllegalArgumentException(whatsit);
    return new ExoticCompositeData(whatsit.substring(1));
}
 
Example 20
Source File: LazyCompositeData.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static int getInt(CompositeData cd, String itemName) {
    if (cd == null)
        throw new IllegalArgumentException("Null CompositeData");

    return ((Integer) cd.get(itemName));
}