/** * Simple merging of metadata by adding the metadata into the message (if mergeMetadata is set to true). * * @param message The parsed message (note: prior to the field transformations) * @param metadata The metadata passed along * @param mergeMetadata Whether to merge the metadata or not * @param config The config for the message strategy. */ @Override public void mergeMetadata(JSONObject message, Map<String, Object> metadata, boolean mergeMetadata, Map<String, Object> config) { if(mergeMetadata) { message.putAll(metadata); } }
private static JSONObject join(JSONObject left, JSONObject right) { JSONObject message = new JSONObject(); message.putAll(left); message.putAll(right); List<Object> emptyKeys = new ArrayList<>(); for(Object key : message.keySet()) { Object value = message.get(key); if(value == null || value.toString().length() == 0) { emptyKeys.add(key); } } for(Object o : emptyKeys) { message.remove(o); } return message; }
@Override public JSONObject enrich(CacheKey k) { String metadata = k.coerceValue(String.class); JSONObject output = new JSONObject(); LOGGER.debug("=======Looking Up For: {}", metadata); output.putAll(getCIFObject(metadata)); return output; }
public byte[] getData() { JSONObject respond = new JSONObject(); respond.put(Payload.TYPE.asKey(), type.toString().toLowerCase()); if (agentDetails != null) { respond.putAll(agentDetails.toJSONObject()); } byte[] ret = getBytes(respond.toJSONString()); if (ret.length > MAX_MSG_SIZE) { throw new IllegalArgumentException("Message to send is larger (" + ret.length + " bytes) than maximum size of " + MAX_MSG_SIZE + " bytes."); } return ret; }
@SuppressWarnings("unchecked") private void addResult(JSONArray ja, SearchResult result) { JSONObject document = new JSONObject(); document.putAll(result.getFields()); document.put("docid", result.getDocId()); document.put("query_relevance_score", result.getScore()); for(Entry<Integer, Double> entry: result.getVariables().entrySet()) { document.put("variable_" + entry.getKey(), entry.getValue()); } for(Entry<String, String> entry: result.getCategories().entrySet()) { document.put("category_" + entry.getKey(), entry.getValue()); } ja.add(document); }
@Override public JSONObject joinMessages(Map<String, Tuple> streamMessageMap, MessageGetStrategy messageGetStrategy) { JSONObject message = new JSONObject(); for (String key : streamMessageMap.keySet()) { Tuple tuple = streamMessageMap.get(key); JSONObject obj = (JSONObject) messageGetStrategy.get(tuple); message.putAll(obj); } List<Object> emptyKeys = new ArrayList<>(); for(Object key : message.keySet()) { Object value = message.get(key); if(value == null || value.toString().length() == 0) { emptyKeys.add(key); } } for(Object o : emptyKeys) { message.remove(o); } message.put(getClass().getSimpleName().toLowerCase() + ".joiner.ts", "" + System.currentTimeMillis()); return message; }
gm.captures(); JSONObject message = new JSONObject(); message.putAll(gm.toMap());
gm.captures(); JSONObject message = new JSONObject(); message.putAll(gm.toMap());
} catch (Throwable e) { JSONObject errorMessage = new JSONObject(); errorMessage.putAll(m); errorMessage.put(Constants.SENSOR_TYPE, sensorType ); errors.add(new AbstractMap.SimpleEntry<>(errorMessage, new IllegalStateException(strategy + " error with " + task.getKey() + " failed: " + e.getMessage(), e)));
/** * Encodes the given Map of parameters to a JSON String. * * @param parameters The Map of parsed parameters * @return The JSON String */ private static String encodeParametersToJSON(Map<String, String> parameters) { JSONObject object = new JSONObject(); object.putAll(parameters); return object.toJSONString(); }
@Override @SuppressWarnings("unchecked") public synchronized void send(Map<String, Object> msg) throws IOException { JSONObject obj = new JSONObject(); obj.putAll(msg); byte[] data = obj.toJSONString().getBytes(Charset.forName("UTF-8")); socket.getOutputStream().write(length.putInt(0, data.length).array()); socket.getOutputStream().write(data); logger.debug("> ({}) {}", HexUtils.bin2hex(length.array()), obj.toJSONString()); }
@Override @SuppressWarnings("unchecked") public synchronized void send(Map<String, Object> msg) throws IOException { JSONObject obj = new JSONObject(); obj.putAll(msg); byte[] data = obj.toJSONString().getBytes(Charset.forName("UTF-8")); socket.getOutputStream().write(length.putInt(0, data.length).array()); socket.getOutputStream().write(data); logger.debug("> ({}) {}", HexUtils.bin2hex(length.array()), obj.toJSONString()); }
@Override public void print(T data, PrintStream out) { JSONObject json = new JSONObject(); json.putAll(data.convert2Map()); out.println(json.toString()); } }
@Override public void print(T data, PrintStream out) { JSONObject json = new JSONObject(); json.putAll(data.convert2Map()); out.println(json.toString()); } }
@Override public void print(T data, PrintStream out) { JSONObject json = new JSONObject(); json.putAll(data.convert2Map()); out.println(json.toString()); } }
public byte[] getData() { JSONObject respond = new JSONObject(); respond.put(Payload.TYPE.asKey(), type.toString().toLowerCase()); if (agentDetails != null) { respond.putAll(agentDetails.toJSONObject()); } byte[] ret = getBytes(respond.toJSONString()); if (ret.length > MAX_MSG_SIZE) { throw new IllegalArgumentException("Message to send is larger (" + ret.length + " bytes) than maximum size of " + MAX_MSG_SIZE + " bytes."); } return ret; }
public byte[] getData() { JSONObject respond = new JSONObject(); respond.put(Payload.TYPE.asKey(), type.toString().toLowerCase()); if (agentDetails != null) { respond.putAll(agentDetails.toJSONObject()); } byte[] ret = getBytes(respond.toJSONString()); if (ret.length > MAX_MSG_SIZE) { throw new IllegalArgumentException("Message to send is larger (" + ret.length + " bytes) than maximum size of " + MAX_MSG_SIZE + " bytes."); } return ret; }
/** {@inheritDoc} */ public JSONObject toJSON() { JSONObject ret = super.toJSON(); JSONObject commandJson = command.toJSON(); ret.putAll(commandJson); return ret; }