@Test public void testPremineFromJSON() throws ParseException { JSONParser parser = new JSONParser(); JSONObject genesisMap = (JSONObject) parser.parse(TEST_GENESIS); Set keys = genesisMap.keySet(); Trie state = new SecureTrie((byte[]) null); for (Object key : keys) { JSONObject val = (JSONObject) genesisMap.get(key); String denom = (String) val.keySet().toArray()[0]; String value = (String) val.values().toArray()[0]; BigInteger wei = Denomination.valueOf(denom.toUpperCase()).value().multiply(new BigInteger(value)); AccountState acctState = new AccountState(BigInteger.ZERO, wei); state.put(Hex.decode(key.toString()), acctState.getEncoded()); } logger.info("root: " + Hex.toHexString(state.getRootHash())); assertEquals(GENESIS_STATE_ROOT, Hex.toHexString(state.getRootHash())); }
private Object navigatePath() { int size = pathStack.size(); JSONObject innerMap = infoMap; while (size > 0) { Collection vals = innerMap.values(); if (vals.size() == 0) { return innerMap; } else if (vals.size() != 1) { throw new IllegalStateException("Internal: More than one key found when extracting with path: " + vals); } Object value = vals.iterator().next(); // End leaf, return it .... if (size == 1) { return value; } // Dive in deeper ... if (!(value instanceof JSONObject)) { throw new IllegalStateException("Internal: Value within path extraction must be a Map, not " + value.getClass()); } innerMap = (JSONObject) value; --size; } return innerMap; } }
private void putRowsToTabularData(TabularDataSupport pTabularData, JSONObject pValue, int pLevel) { TabularType type = pTabularData.getTabularType(); for (Object value : pValue.values()) { if (!(value instanceof JSONObject)) { throw new IllegalArgumentException( "Cannot convert " + pValue + " to type " + type + " because the object values provided (" + value.getClass() + ") is not of the expected type JSONObject at level " + pLevel); } JSONObject jsonValue = (JSONObject) value; if (pLevel > 1) { putRowsToTabularData(pTabularData, jsonValue, pLevel - 1); } else { pTabularData.put((CompositeData) getDispatcher().convertToObject(type.getRowType(), jsonValue)); } } } }
public static ObjectName getRoot(J4pClient client) throws Exception { String type = "org.apache.activemq:*,type=Broker"; String attribute = "BrokerName"; ObjectName objectName = new ObjectName(type); J4pResponse<J4pReadRequest> response = client.execute(new J4pReadRequest(objectName, attribute)); JSONObject jsonObject = response.getValue(); JSONObject nameObject = (JSONObject) jsonObject.values().iterator().next(); String name = nameObject.values().iterator().next().toString(); return new ObjectName("org.apache.activemq:type=Broker,brokerName=" + name); }
public static ObjectName getRoot(J4pClient client) throws Exception { String type = "org.apache.activemq:*,type=Broker"; String attribute = "BrokerName"; ObjectName objectName = new ObjectName(type); J4pResponse<J4pReadRequest> response = client.execute(new J4pReadRequest(objectName, attribute)); JSONObject jsonObject = response.getValue(); JSONObject nameObject = (JSONObject) jsonObject.values().iterator().next(); String name = nameObject.values().iterator().next().toString(); return new ObjectName("org.apache.activemq:type=Broker,brokerName=" + name); }
private Object navigatePath() { int size = pathStack.size(); JSONObject innerMap = infoMap; while (size > 0) { Collection vals = innerMap.values(); if (vals.size() == 0) { return innerMap; } else if (vals.size() != 1) { throw new IllegalStateException("Internal: More than one key found when extracting with path: " + vals); } Object value = vals.iterator().next(); // End leaf, return it .... if (size == 1) { return value; } // Dive in deeper ... if (!(value instanceof JSONObject)) { throw new IllegalStateException("Internal: Value within path extraction must be a Map, not " + value.getClass()); } innerMap = (JSONObject) value; --size; } return innerMap; } }
private Object navigatePath() { int size = pathStack.size(); JSONObject innerMap = infoMap; while (size > 0) { Collection vals = innerMap.values(); if (vals.size() == 0) { return innerMap; } else if (vals.size() != 1) { throw new IllegalStateException("Internal: More than one key found when extracting with path: " + vals); } Object value = vals.iterator().next(); // End leaf, return it .... if (size == 1) { return value; } // Dive in deeper ... if (!(value instanceof JSONObject)) { throw new IllegalStateException("Internal: Value within path extraction must be a Map, not " + value.getClass()); } innerMap = (JSONObject) value; --size; } return innerMap; } }
@Override public List<Map<String, Object>> browseInflightExchanges(String camelContextName, String route, int limit, boolean sortByLongestDuration) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } List<Map<String, Object>> answer = new ArrayList<>(); ObjectName found = lookupCamelContext(camelContextName); if (found != null) { String pattern = String.format("%s:context=%s,type=services,name=DefaultInflightRepository", found.getDomain(), found.getKeyProperty("context")); ObjectName on = ObjectName.getInstance(pattern); J4pExecResponse er = jolokia.execute(new J4pExecRequest(on, "browse(String,int,boolean)", route, limit, sortByLongestDuration)); if (er != null) { JSONObject data = er.getValue(); if (data != null) { for (Object obj : data.values()) { JSONObject inflight = (JSONObject) obj; Map<String, Object> row = new LinkedHashMap<>(); row.put("exchangeId", asString(inflight.get("exchangeId"))); row.put("fromRouteId", asString(inflight.get("fromRouteId"))); row.put("routeId", asString(inflight.get("routeId"))); row.put("nodeId", asString(inflight.get("nodeId"))); row.put("elapsed", asString(inflight.get("elapsed"))); row.put("duration", asString(inflight.get("duration"))); answer.add(row); } } } } return answer; }
if (response != null) { JSONObject data = response.getValue(); for (Object obj : data.values()) { JSONObject component = (JSONObject) obj;
private void putRowsToTabularData(TabularDataSupport pTabularData, JSONObject pValue, int pLevel) { TabularType type = pTabularData.getTabularType(); for (Object value : pValue.values()) { if (!(value instanceof JSONObject)) { throw new IllegalArgumentException( "Cannot convert " + pValue + " to type " + type + " because the object values provided (" + value.getClass() + ") is not of the expected type JSONObject at level " + pLevel); } JSONObject jsonValue = (JSONObject) value; if (pLevel > 1) { putRowsToTabularData(pTabularData, jsonValue, pLevel - 1); } else { pTabularData.put((CompositeData) getDispatcher().convertToObject(type.getRowType(), jsonValue)); } } } }
private void putRowsToTabularData(TabularDataSupport pTabularData, JSONObject pValue, int pLevel) { TabularType type = pTabularData.getTabularType(); for (Object value : pValue.values()) { if (!(value instanceof JSONObject)) { throw new IllegalArgumentException( "Cannot convert " + pValue + " to type " + type + " because the object values provided (" + value.getClass() + ") is not of the expected type JSONObject at level " + pLevel); } JSONObject jsonValue = (JSONObject) value; if (pLevel > 1) { putRowsToTabularData(pTabularData, jsonValue, pLevel - 1); } else { pTabularData.put((CompositeData) getDispatcher().convertToObject(type.getRowType(), jsonValue)); } } } }
private void putRowsToTabularData(TabularDataSupport pTabularData, JSONObject pValue, int pLevel) { TabularType type = pTabularData.getTabularType(); for (Object value : pValue.values()) { if (!(value instanceof JSONObject)) { throw new IllegalArgumentException( "Cannot convert " + pValue + " to type " + type + " because the object values provided (" + value.getClass() + ") is not of the expected type JSONObject at level " + pLevel); } JSONObject jsonValue = (JSONObject) value; if (pLevel > 1) { putRowsToTabularData(pTabularData, jsonValue, pLevel - 1); } else { pTabularData.put((CompositeData) getDispatcher().deserialize(type.getRowType(), jsonValue)); } } } }