List of usage examples for org.json.simple JSONObject size
int size();
From source file:org.jolokia.converter.json.TabularDataExtractorTest.java
@Test void extractGenericTabularDataWithIntegerAndObjectNamePath() throws OpenDataException, AttributeNotFoundException, MalformedObjectNameException { TabularTypeAndJson taj = new TabularTypeAndJson(new String[] { "bundleId", "oName" }, new CompositeTypeAndJson(LONG, "bundleId", null, OBJECTNAME, "oName", null, BOOLEAN, "active", null));/*from ww w . ja va2 s. co m*/ TabularData data = new TabularDataSupport(taj.getType()); data.put( new CompositeDataSupport(taj.getType().getRowType(), new String[] { "bundleId", "oName", "active" }, new Object[] { 10L, new ObjectName("test:type=bundle"), false })); JSONObject result = (JSONObject) extract(true, data, "10", "test:type=bundle"); assertEquals(result.size(), 3); assertEquals(result.get("bundleId"), 10L); assertEquals(result.get("active"), false); }
From source file:org.jolokia.converter.json.TabularDataExtractorTest.java
@Test public void extractWithWildCardPath() throws OpenDataException, MalformedObjectNameException, AttributeNotFoundException { TabularTypeAndJson taj = new TabularTypeAndJson(new String[] { "id" }, new CompositeTypeAndJson(LONG, "id", null, OBJECTNAME, "oName", null, BOOLEAN, "flag", null)); TabularData data = new TabularDataSupport(taj.getType()); data.put(new CompositeDataSupport(taj.getType().getRowType(), new String[] { "id", "oName", "flag" }, new Object[] { 10L, new ObjectName("test:type=bundle"), false })); data.put(new CompositeDataSupport(taj.getType().getRowType(), new String[] { "id", "oName", "flag" }, new Object[] { 20L, new ObjectName("java.lang:type=Memory"), true })); // Path: */*/domain --> 1. Level: 10, 20 -- 2. Level: CD key-value (e.g {id: 10, oName: test=type...}), -- 3. level: Objects // Here: Only ObjetNames should be picked JSONObject result = (JSONObject) extract(true, data, null, null, "domain"); assertEquals(result.size(), 2); // 10 & 20 JSONObject inner = (JSONObject) result.get(10L); assertEquals(inner.size(), 1);/*from ww w . j av a 2 s . com*/ assertEquals(inner.get("oName"), "test"); inner = (JSONObject) result.get(20L); assertEquals(inner.size(), 1); assertEquals(inner.get("oName"), "java.lang"); // Path: */oName --> 1. Level: 10,20 -- 2. Level: { oName : { 10 vals}} result = (JSONObject) extract(true, data, null, "oName"); assertEquals(result.size(), 2); inner = (JSONObject) result.get(10L); assertEquals(inner.get("domain"), "test"); inner = (JSONObject) result.get(20L); assertEquals(inner.get("domain"), "java.lang"); }
From source file:org.jolokia.converter.json.TabularDataExtractorTest.java
@Test void emptyMxMBeanTabularData() throws MalformedObjectNameException, OpenDataException, AttributeNotFoundException { TabularData data = prepareMxMBeanMapData(); JSONObject result = (JSONObject) extract(true, data); assertNotNull(result);/*from w ww . j av a2 s. co m*/ assertEquals(result.size(), 0); }
From source file:org.jolokia.converter.json.TabularDataExtractorTest.java
@Test void emptyTabularData() throws MalformedObjectNameException, OpenDataException, AttributeNotFoundException { CompositeType type = new CompositeType("testType", "Type for testing", new String[] { "testKey" }, new String[] { "bla" }, new OpenType[] { STRING }); TabularData data = new TabularDataSupport( new TabularType("test", "test desc", type, new String[] { "testKey" })); JSONObject result = (JSONObject) extract(true, data); assertNotNull(result);/*w w w . j a v a2s . co m*/ assertEquals(result.size(), 0); }
From source file:org.jolokia.converter.object.TabularDataConverter.java
private boolean checkForFullTabularDataRepresentation(JSONObject pValue, TabularType pType) { if (pValue.containsKey("indexNames") && pValue.containsKey("values") && pValue.size() == 2) { Object jsonVal = pValue.get("indexNames"); if (!(jsonVal instanceof JSONArray)) { throw new IllegalArgumentException( "Index names for tabular data must given as JSON array, not " + jsonVal.getClass()); }/* www. ja v a2s . c o m*/ JSONArray indexNames = (JSONArray) jsonVal; List<String> tabularIndexNames = pType.getIndexNames(); if (indexNames.size() != tabularIndexNames.size()) { throw new IllegalArgumentException( "Given array with index names must have " + tabularIndexNames.size() + " entries " + "(given: " + indexNames + ", required: " + tabularIndexNames + ")"); } for (Object index : indexNames) { if (!tabularIndexNames.contains(index.toString())) { throw new IllegalArgumentException("No index with name '" + index + "' known " + "(given: " + indexNames + ", required: " + tabularIndexNames + ")"); } } return true; } return false; }
From source file:org.jolokia.detector.WebsphereDetector.java
/** {@inheritDoc} * @param pMBeanServerExecutor*///from ww w . ja va 2s . c om public ServerHandle detect(MBeanServerExecutor pMBeanServerExecutor) { String serverVersion = getSingleStringAttribute(pMBeanServerExecutor, "*:j2eeType=J2EEServer,type=Server,*", "serverVersion"); if (serverVersion != null && serverVersion.contains("WebSphere")) { Matcher matcher = SERVER_VERSION_PATTERN.matcher(serverVersion); if (matcher.find()) { String version = matcher.group(1); String date = matcher.group(2); JSONObject extraInfo = new JSONObject(); if (date != null) { extraInfo.put("buildDate", date); } return new WebsphereServerHandle(version, extraInfo.size() > 0 ? extraInfo : null); } return null; } else if (isWebsphere) { return new WebsphereServerHandle(isWebsphere6 ? "6" : "7 or 8", null); } return null; }
From source file:org.jolokia.handler.list.DataUpdater.java
/** * Update the given JSON object with the data extracted from the given * MBeanInfo//from www. jav a 2 s . c om * * @param pJSONObject JSON object to update * @param pMBeanInfo info to extract from * @param pPathStack stack for further constraining the result */ void update(JSONObject pJSONObject, MBeanInfo pMBeanInfo, Stack<String> pPathStack) { boolean isPathEmpty = pPathStack == null || pPathStack.empty(); String filter = pPathStack != null && !pPathStack.empty() ? pPathStack.pop() : null; verifyThatPathIsEmpty(pPathStack); JSONObject attrMap = extractData(pMBeanInfo, filter); if (attrMap.size() > 0) { pJSONObject.put(getKey(), attrMap); } else if (!isPathEmpty) { throw new IllegalArgumentException("Path given but extracted value is empty"); } }
From source file:org.jolokia.handler.list.MBeanInfoData.java
/** * Add information about an MBean as obtained from an {@link MBeanInfo} descriptor. The information added * can be restricted by a given path (which has already be prepared as a stack). Also, a max depth as given in the * constructor restricts the size of the map from the top. * * @param mBeanInfo the MBean info//from w ww . j a v a 2 s .c o m * @param pName the object name of the MBean */ public void addMBeanInfo(MBeanInfo mBeanInfo, ObjectName pName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { JSONObject mBeansMap = getOrCreateJSONObject(infoMap, pName.getDomain()); JSONObject mBeanMap = getOrCreateJSONObject(mBeansMap, getKeyPropertyString(pName)); // Trim down stack to get rid of domain/property list Stack<String> stack = truncatePathStack(2); if (stack.empty()) { addFullMBeanInfo(mBeanMap, mBeanInfo); } else { addPartialMBeanInfo(mBeanMap, mBeanInfo, stack); } // Trim if required if (mBeanMap.size() == 0) { mBeansMap.remove(getKeyPropertyString(pName)); if (mBeansMap.size() == 0) { infoMap.remove(pName.getDomain()); } } }
From source file:org.jolokia.history.HistoryStore.java
private void updateReadHistory(JmxReadRequest pJmxReq, JSONObject pJson, long pTimestamp) { ObjectName name = pJmxReq.getObjectName(); if (name.isPattern()) { // We have a pattern and hence a value structure // of bean -> attribute_key -> attribute_value Map<String, Object> values = (Map<String, Object>) pJson.get(KEY_VALUE); // Can be null if used with path and no single match occurred if (values != null) { JSONObject history = updateHistoryForPatternRead(pJmxReq, pTimestamp, values); if (history.size() > 0) { pJson.put(KEY_HISTORY, history); }/*w w w . j a v a 2 s. c o m*/ } } else if (pJmxReq.isMultiAttributeMode() || !pJmxReq.hasAttribute()) { // Multiple attributes, but a single bean. // Value has the following structure: // attribute_key -> attribute_value JSONObject history = addMultipleAttributeValues(pJmxReq, ((Map<String, Object>) pJson.get(KEY_VALUE)), pJmxReq.getObjectNameAsString(), pTimestamp); if (history.size() > 0) { pJson.put(KEY_HISTORY, history); } } else { // Single attribute, single bean. Value is the attribute_value // itself. addAttributeFromSingleValue(pJson, new HistoryKey(pJmxReq), KEY_HISTORY, pJson.get(KEY_VALUE), pTimestamp); } }
From source file:org.jolokia.history.HistoryStore.java
private JSONObject updateHistoryForPatternRead(JmxReadRequest pJmxReq, long pTimestamp, Map<String, Object> pValues) { JSONObject history = new JSONObject(); List<String> pathParts = pJmxReq.getPathParts(); if (pathParts != null && pathParts.size() == 1) { return updateHistoryForPatternReadWithMBeanAsPath(pJmxReq, pTimestamp, pValues); }/*from w ww.ja v a 2s. co m*/ for (Map.Entry<String, Object> beanEntry : pValues.entrySet()) { JSONObject beanHistory = null; String beanName = beanEntry.getKey(); Object value = beanEntry.getValue(); if (pathParts != null && pathParts.size() == 2) { beanHistory = addPathFilteredAttributeValue(pJmxReq, pTimestamp, beanName, value); } if (value instanceof Map) { beanHistory = addMultipleAttributeValues(pJmxReq, ((Map<String, Object>) beanEntry.getValue()), beanName, pTimestamp); } if (beanHistory != null && beanHistory.size() > 0) { history.put(beanName, beanHistory); } } return history; }