/** * Whether there are any relay message attached to this message. * * @return */ public boolean hasRelayMessages() { List<String> relayHosts = _record.getListField(Attributes.RELAY_PARTICIPANTS.name()); return (relayHosts != null && relayHosts.size() > 0); }
/** * Get all relay messages attached to this message as a map (instance->message). * * @return map of instanceName->message, empty map if none. */ public Map<String, Message> getRelayMessages() { Map<String, Message> relayMessageMap = new HashMap<>(); List<String> relayParticipants = _record.getListField(Attributes.RELAY_PARTICIPANTS.name()); if (relayParticipants != null) { for (String p : relayParticipants) { Message msg = getRelayMessage(p); if (p != null) { relayMessageMap.put(p, msg); } } } return relayMessageMap; }
/** * Get all relay messages attached to this message as a map (instance->message). * * @return map of instanceName->message, empty map if none. */ public Map<String, Message> getRelayMessages() { Map<String, Message> relayMessageMap = new HashMap<>(); List<String> relayParticipants = _record.getListField(Attributes.RELAY_PARTICIPANTS.name()); if (relayParticipants != null) { for (String p : relayParticipants) { Message msg = getRelayMessage(p); if (p != null) { relayMessageMap.put(p, msg); } } } return relayMessageMap; }
/** * Attach a relayed message and its destination participant to this message. * * WARNNING: only content in SimpleFields of relayed message will be carried over and sent, * all contents in either ListFields or MapFields will be ignored. * * @param instance destination participant name * @param message relayed message. */ public void attachRelayMessage(String instance, Message message) { List<String> relayList = _record.getListField(Attributes.RELAY_PARTICIPANTS.name()); if (relayList == null) { relayList = Collections.EMPTY_LIST; } Set<String> relayParticipants = new LinkedHashSet<>(relayList); relayParticipants.add(instance); Map<String, String> messageInfo = message.getRecord().getSimpleFields(); messageInfo.put(Attributes.RELAY_MSG_ID.name(), message.getId()); messageInfo.put(Attributes.MSG_SUBTYPE.name(), MessageType.RELAYED_MESSAGE.name()); messageInfo.put(Attributes.RELAY_FROM.name(), getTgtName()); messageInfo .put(Attributes.EXPIRY_PERIOD.name(), String.valueOf(RELAY_MESSAGE_DEFAULT_EXPIRY)); _record.setMapField(instance, messageInfo); _record.setListField(Attributes.RELAY_PARTICIPANTS.name(), Lists.newArrayList(relayParticipants)); }
/** * Get relay message attached for the given instance. * * @param instance * @return null if no message for the instance */ public Message getRelayMessage(String instance) { Map<String, String> messageInfo = _record.getMapField(instance); if (messageInfo != null) { String id = messageInfo.get(Attributes.RELAY_MSG_ID.name()); if (id == null) { id = messageInfo.get(Attributes.MSG_ID.name()); if (id == null) { return null; } } ZNRecord record = new ZNRecord(id); record.setSimpleFields(messageInfo); return new Message(record); } return null; }
public String getRelaySrcHost() { return _record.getSimpleField(Attributes.RELAY_FROM.name()); }
public String getRelaySrcHost() { return _record.getSimpleField(Attributes.RELAY_FROM.name()); }
/** * Whether there are any relay message attached to this message. * * @return */ public boolean hasRelayMessages() { List<String> relayHosts = _record.getListField(Attributes.RELAY_PARTICIPANTS.name()); return (relayHosts != null && relayHosts.size() > 0); }
/** * Set the completion time of previous task associated with this message. * This applies only when this is a relay message, * which specified the completion time of the task running on the participant that sent this relay message. * * @param completionTime */ public void setRelayTime(long completionTime) { _record.setLongField(Attributes.RELAY_TIME.name(), completionTime); }
/** * Get the completion time of previous task associated with this message. * This applies only when this is a relay message, * which specified the completion time of the task running on the participant that sent this relay message. * * @return */ public long getRelayTime() { return _record.getLongField(Attributes.RELAY_TIME.name(), -1); }
/** * Set the source cluster name * @param clusterName source cluster name where message was sent from */ public void setSrcClusterName(String clusterName) { _record.setSimpleField(Attributes.SRC_CLUSTER.name(), clusterName); }
/** * Set expiry period for this message. * A message will be expired after this period of time from either its 1) creationTime or 2) * relayTime if it is relay message. * Default is -1 if it is not set. * * @param expiry */ public void setExpiryPeriod(long expiry) { _record.setLongField(Attributes.EXPIRY_PERIOD.name(), expiry); }
/** * Whether this message is a relay message. * @return */ public boolean isRelayMessage() { String subType = _record.getStringField(Attributes.MSG_SUBTYPE.name(), null); String relayFrom = _record.getStringField(Attributes.RELAY_FROM.name(), null); return MessageType.RELAYED_MESSAGE.name().equals(subType) && (relayFrom != null); }
/** * Set expiry period for this message. * A message will be expired after this period of time from either its 1) creationTime or 2) * relayTime if it is relay message. * Default is -1 if it is not set. * * @param expiry */ public void setExpiryPeriod(long expiry) { _record.setLongField(Attributes.EXPIRY_PERIOD.name(), expiry); }
/** * Get the completion time of previous task associated with this message. * This applies only when this is a relay message, * which specified the completion time of the task running on the participant that sent this relay message. * * @return */ public long getRelayTime() { return _record.getLongField(Attributes.RELAY_TIME.name(), -1); }
/** * Whether this message is a relay message. * @return */ public boolean isRelayMessage() { String subType = _record.getStringField(Attributes.MSG_SUBTYPE.name(), null); String relayFrom = _record.getStringField(Attributes.RELAY_FROM.name(), null); return MessageType.RELAYED_MESSAGE.name().equals(subType) && (relayFrom != null); }
/** * Set the completion time of previous task associated with this message. * This applies only when this is a relay message, * which specified the completion time of the task running on the participant that sent this relay message. * * @param completionTime */ public void setRelayTime(long completionTime) { _record.setLongField(Attributes.RELAY_TIME.name(), completionTime); }
/** * Get the source cluster name * @return the source cluster from where the message was sent or null if the message was sent locally */ public String getSrcClusterName() { return _record.getStringField(Attributes.SRC_CLUSTER.name(), null); }
/** * Get the expiry period (in milliseconds) * * @return */ public long getExpiryPeriod() { return _record.getLongField(Attributes.EXPIRY_PERIOD.name(), -1); }
/** * Get the expiry period (in milliseconds) * * @return */ public long getExpiryPeriod() { return _record.getLongField(Attributes.EXPIRY_PERIOD.name(), -1); }