@Override public Object deserialize(byte[] b) { try { return JSONValue.parseWithException(new String(b, "UTF-8")); } catch (UnsupportedEncodingException | ParseException e) { throw new RuntimeException(e); } }
private static String mergeIntoJson(Map<String, Object> into, Map<String, Object> newMap) { Map<String, Object> res = new HashMap<>(into); res.putAll(newMap); return JSONValue.toJSONString(res); }
public Number connect(Map<String, Object> conf, TopologyContext context) throws IOException, NoOutputException { JSONObject setupInfo = new JSONObject(); setupInfo.put("pidDir", context.getPIDDir()); setupInfo.put("conf", conf); setupInfo.put("context", context); writeMessage(setupInfo); Number pid = (Number) ((JSONObject) readMessage()).get("pid"); return pid; }
@SuppressWarnings("unchecked") public static boolean isValidConf(Map<String, Object> topoConfIn) { Map<String, Object> origTopoConf = normalizeConf(topoConfIn); try { Map<String, Object> deserTopoConf = normalizeConf( (Map<String, Object>) JSONValue.parseWithException(JSONValue.toJSONString(topoConfIn))); return isValidConf(origTopoConf, deserTopoConf); } catch (ParseException e) { LOG.error("Json serialized config could not be deserialized", e); } return false; }
public void writeBoltMsg(BoltMsg boltMsg) throws IOException { JSONObject obj = new JSONObject(); obj.put("id", boltMsg.getId()); obj.put("comp", boltMsg.getComp()); obj.put("stream", boltMsg.getStream()); obj.put("task", boltMsg.getTask()); obj.put("tuple", boltMsg.getTuple()); writeMessage(obj); }
public static byte[] toCompressedJsonConf(Map<String, Object> topoConf) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStreamWriter out = new OutputStreamWriter(new GZIPOutputStream(bos)); JSONValue.writeJSONString(topoConf, out); out.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public String toJSONString() { Map<String, Object> obj = new HashMap<>(); obj.put("task->component", _taskToComponent); // TODO: jsonify StormTopology // at the minimum should send source info return JSONValue.toJSONString(obj); }
public void writeSpoutMsg(SpoutMsg msg) throws IOException { JSONObject obj = new JSONObject(); obj.put("command", msg.getCommand()); obj.put("id", msg.getId()); writeMessage(obj); }
public static Map<String, Object> parseJson(String json) { if (json == null) { return new HashMap<>(); } else { try { return (Map<String, Object>) JSONValue.parseWithException(json); } catch (ParseException e) { throw new RuntimeException(e); } } }
@Override public byte[] serialize(Object obj) { try { return JSONValue.toJSONString(obj).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
private Object readMessage() throws IOException, NoOutputException { try { return JSONValue.parseWithException(readString()); } catch (ParseException e) { throw new IOException(e); } }
private void writeMessage(Object msg) throws IOException { writeString(JSONValue.toJSONString(msg)); }
public static Map<String, Object> fromCompressedJsonConf(byte[] serialized) { try { ByteArrayInputStream bis = new ByteArrayInputStream(serialized); InputStreamReader in = new InputStreamReader(new GZIPInputStream(bis)); Object ret = JSONValue.parseWithException(in); in.close(); return (Map<String, Object>) ret; } catch (IOException | ParseException e) { throw new RuntimeException(e); } }
@Override public byte[] serialize(OpaqueValue obj) { List toSer = new ArrayList(3); toSer.add(obj.currTxid); toSer.add(obj.curr); toSer.add(obj.prev); try { return JSONValue.toJSONString(toSer).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
@Override public TransactionalValue deserialize(byte[] b) { try { String s = new String(b, "UTF-8"); List deser = (List) JSONValue.parseWithException(s); return new TransactionalValue((Long) deser.get(0), deser.get(1)); } catch (UnsupportedEncodingException | ParseException e) { throw new RuntimeException(e); } }
@Override public T addResources(Map<String, Double> resources) { if (resources != null && !resources.isEmpty()) { String currConf = commons.get(id).get_json_conf(); Map<String, Object> conf = parseJson(currConf); Map<String, Double> currentResources = (Map<String, Double>) conf.computeIfAbsent(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, (k) -> new HashMap<>()); currentResources.putAll(resources); commons.get(id).set_json_conf(JSONValue.toJSONString(conf)); } return (T) this; }
@Override public OpaqueValue deserialize(byte[] b) { try { String s = new String(b, "UTF-8"); List deser = (List) JSONValue.parseWithException(s); return new OpaqueValue((Long) deser.get(0), deser.get(1), deser.get(2)); } catch (UnsupportedEncodingException | ParseException e) { throw new RuntimeException(e); } }
@Override public byte[] serialize(TransactionalValue obj) { List toSer = new ArrayList(2); toSer.add(obj.getTxid()); toSer.add(obj.getVal()); try { return JSONValue.toJSONString(toSer).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
@Override public void execute(TridentTuple input, TridentCollector collector) { try { String args = input.getString(0); List<List<Object>> tuples = (List) JSONValue.parseWithException(args); for (List<Object> tuple : tuples) { collector.emit(tuple); } } catch (ParseException e) { throw new RuntimeException(e); } } }
public static ComponentCommon prepareComponentCommon(Map<GlobalStreamId, Grouping> inputs, Map<String, StreamInfo> outputs, Integer parallelismHint, Map<String, Object> conf) { Map<GlobalStreamId, Grouping> mappedInputs = new HashMap<>(); Map<String, StreamInfo> mappedOutputs = new HashMap<>(); if (inputs != null && !inputs.isEmpty()) { mappedInputs.putAll(inputs); } if (outputs != null && !outputs.isEmpty()) { mappedOutputs.putAll(outputs); } ComponentCommon component = new ComponentCommon(mappedInputs, mappedOutputs); if (parallelismHint != null) { component.set_parallelism_hint(parallelismHint); } if (conf != null) { component.set_json_conf(JSONValue.toJSONString(conf)); } return component; }