Java Code Examples for javax.management.openmbean.CompositeData#getCompositeType()
The following examples show how to use
javax.management.openmbean.CompositeData#getCompositeType() .
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: AttributeHelper.java From cuba with Apache License 2.0 | 5 votes |
private static Object convertToTrueObject(CompositeData compositeData) { CompositeType type = compositeData.getCompositeType(); try { Class<?> _class = Class.forName(type.getTypeName()); Method method = _class.getMethod("from", CompositeData.class); if (Modifier.isStatic(method.getModifiers()) && method.getReturnType() == _class) { return method.invoke(null, compositeData); } return null; } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new RuntimeException(e); } }
Example 2
Source File: StackTraceElementCompositeData.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** 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 ct = cd.getCompositeType(); if (!isTypeMatched(stackTraceElementCompositeType, ct)) { if (!isTypeMatched(stackTraceElementV6CompositeType, ct)) { throw new IllegalArgumentException( "Unexpected composite type for StackTraceElement"); } } }
Example 3
Source File: AttributeHelper.java From cuba with Apache License 2.0 | 5 votes |
private static String compositeToString(CompositeData compositeData) { if (canConvertToTrueObject(compositeData)) { try { Object trueObject = convertToTrueObject(compositeData); return String.valueOf(trueObject); } catch (Exception e) { return e.getClass().getName() + " " + e.getMessage(); } } CompositeType type = compositeData.getCompositeType(); StringBuilder b = new StringBuilder(); b.append("["); List<String> keys = new ArrayList<>(type.keySet()); Collections.sort(keys); // alphabetically for (String key: keys) { b.append(key).append(": "); Object value = compositeData.get(key); b.append(convertToString(value)); if (keys.indexOf(key) != keys.size() - 1) { b.append(", "); } } b.append("]\n"); return b.toString(); }
Example 4
Source File: VMOptionOpenDataTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void validateType(CompositeData data) { CompositeType type = data.getCompositeType(); Set<String> keys = Arrays.stream(names).collect(Collectors.toSet()); if (!type.keySet().equals(keys)) { throw new RuntimeException("key not matched: " + type.keySet().toString()); } for (int i=0; i < names.length; i++) { OpenType t = type.getType(names[i]); if (t != types[i]) { throw new AssertionError(names[i] + ": type not matched: " + t + " expected: " + types[i]); } } }
Example 5
Source File: JMXJsonServlet.java From hadoop with Apache License 2.0 | 5 votes |
private void writeObject(JsonGenerator jg, Object value) throws IOException { if(value == null) { jg.writeNull(); } else { Class<?> c = value.getClass(); if (c.isArray()) { jg.writeStartArray(); int len = Array.getLength(value); for (int j = 0; j < len; j++) { Object item = Array.get(value, j); writeObject(jg, item); } jg.writeEndArray(); } else if(value instanceof Number) { Number n = (Number)value; jg.writeNumber(n.toString()); } else if(value instanceof Boolean) { Boolean b = (Boolean)value; jg.writeBoolean(b); } else if(value instanceof CompositeData) { CompositeData cds = (CompositeData)value; CompositeType comp = cds.getCompositeType(); Set<String> keys = comp.keySet(); jg.writeStartObject(); for(String key: keys) { writeAttribute(jg, key, cds.get(key)); } jg.writeEndObject(); } else if(value instanceof TabularData) { TabularData tds = (TabularData)value; jg.writeStartArray(); for(Object entry : tds.values()) { writeObject(jg, entry); } jg.writeEndArray(); } else { jg.writeString(value.toString()); } } }
Example 6
Source File: JMXJsonServlet.java From big-c with Apache License 2.0 | 5 votes |
private void writeObject(JsonGenerator jg, Object value) throws IOException { if(value == null) { jg.writeNull(); } else { Class<?> c = value.getClass(); if (c.isArray()) { jg.writeStartArray(); int len = Array.getLength(value); for (int j = 0; j < len; j++) { Object item = Array.get(value, j); writeObject(jg, item); } jg.writeEndArray(); } else if(value instanceof Number) { Number n = (Number)value; jg.writeNumber(n.toString()); } else if(value instanceof Boolean) { Boolean b = (Boolean)value; jg.writeBoolean(b); } else if(value instanceof CompositeData) { CompositeData cds = (CompositeData)value; CompositeType comp = cds.getCompositeType(); Set<String> keys = comp.keySet(); jg.writeStartObject(); for(String key: keys) { writeAttribute(jg, key, cds.get(key)); } jg.writeEndObject(); } else if(value instanceof TabularData) { TabularData tds = (TabularData)value; jg.writeStartArray(); for(Object entry : tds.values()) { writeObject(jg, entry); } jg.writeEndArray(); } else { jg.writeString(value.toString()); } } }
Example 7
Source File: ThreadInfoCompositeData.java From hottub with GNU General Public License v2.0 | 4 votes |
/** 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 8
Source File: ThreadInfoCompositeData.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** 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 9
Source File: ThreadInfoCompositeData.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** 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 10
Source File: SdcInfoContentGenerator.java From datacollector with Apache License 2.0 | 4 votes |
private void writeObject(JsonGenerator jg, Object value) throws IOException { if(value == null) { jg.writeNull(); } else { Class<?> c = value.getClass(); if (c.isArray()) { jg.writeStartArray(); int len = Array.getLength(value); for (int j = 0; j < len; j++) { Object item = Array.get(value, j); writeObject(jg, item); } jg.writeEndArray(); } else if(value instanceof Number) { Number n = (Number)value; if (value instanceof Double && (((Double) value).isInfinite() || ((Double) value).isNaN())) { jg.writeString(n.toString()); } else { jg.writeNumber(n.toString()); } } else if(value instanceof Boolean) { Boolean b = (Boolean)value; jg.writeBoolean(b); } else if(value instanceof CompositeData) { CompositeData cds = (CompositeData)value; CompositeType comp = cds.getCompositeType(); Set<String> keys = comp.keySet(); jg.writeStartObject(); for(String key: keys) { writeAttribute(jg, key, cds.get(key)); } jg.writeEndObject(); } else if(value instanceof TabularData) { TabularData tds = (TabularData)value; jg.writeStartArray(); for(Object entry : tds.values()) { writeObject(jg, entry); } jg.writeEndArray(); } else if (value instanceof GaugeValue) { ((GaugeValue)value).serialize(jg); } else { jg.writeString(value.toString()); } } }
Example 11
Source File: ThreadInfoCompositeData.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** 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 12
Source File: ThreadInfoCompositeData.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** 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 13
Source File: ThreadInfoCompositeData.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** 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 14
Source File: ThreadInfoCompositeData.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** 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 15
Source File: ThreadInfoCompositeData.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** 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 16
Source File: ThreadInfoCompositeData.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** 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) && !isTypeMatched(threadInfoV6CompositeType, 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: JSONBean.java From hbase with Apache License 2.0 | 4 votes |
private static void writeObject(JsonWriter writer, Object value) throws IOException { if (value == null) { writer.nullValue(); } else { Class<?> c = value.getClass(); if (c.isArray()) { writer.beginArray(); int len = Array.getLength(value); for (int j = 0; j < len; j++) { Object item = Array.get(value, j); writeObject(writer, item); } writer.endArray(); } else if (value instanceof Number) { Number n = (Number) value; if (Double.isFinite(n.doubleValue())) { writer.value(n); } else { writer.value(n.toString()); } } else if (value instanceof Boolean) { Boolean b = (Boolean) value; writer.value(b); } else if (value instanceof CompositeData) { CompositeData cds = (CompositeData) value; CompositeType comp = cds.getCompositeType(); Set<String> keys = comp.keySet(); writer.beginObject(); for (String key : keys) { writeAttribute(writer, key, null, cds.get(key)); } writer.endObject(); } else if (value instanceof TabularData) { TabularData tds = (TabularData) value; writer.beginArray(); for (Object entry : tds.values()) { writeObject(writer, entry); } writer.endArray(); } else { writer.value(value.toString()); } } }
Example 18
Source File: ThreadInfoCompositeData.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** 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: ThreadInfoCompositeData.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** 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 20
Source File: ThreadInfoCompositeData.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** 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."); } } } }