예제 #1
0
 /**
  * Instantiate a message
  *
  * @param type {@link MessageType} as a string or a custom message type
  * @param msgId unique message identifier
  */
 public Message(String type, MessageId msgId) {
   super(new ZNRecord(msgId.stringify()));
   _record.setSimpleField(Attributes.MSG_TYPE.toString(), type);
   setMessageId(msgId);
   setMsgState(MessageState.NEW);
   _record.setLongField(Attributes.CREATE_TIMESTAMP.toString(), new Date().getTime());
 }
예제 #2
0
 /**
  * Create a reply based on an incoming message
  *
  * @param srcMessage the incoming message
  * @param instanceName the instance that is the source of the reply
  * @param taskResultMap the result of executing the incoming message
  * @return the reply Message
  */
 public static Message createReplyMessage(
     Message srcMessage, String instanceName, Map<String, String> taskResultMap) {
   if (srcMessage.getCorrelationId() == null) {
     throw new HelixException(
         "Message " + srcMessage.getMessageId() + " does not contain correlation id");
   }
   Message replyMessage =
       new Message(MessageType.TASK_REPLY, MessageId.from(UUID.randomUUID().toString()));
   replyMessage.setCorrelationId(srcMessage.getCorrelationId());
   replyMessage.setResultMap(taskResultMap);
   replyMessage.setTgtSessionId(SessionId.from("*"));
   replyMessage.setMsgState(MessageState.NEW);
   replyMessage.setSrcName(instanceName);
   if (srcMessage.getSrcInstanceType() == InstanceType.CONTROLLER) {
     replyMessage.setTgtName("Controller");
   } else {
     replyMessage.setTgtName(srcMessage.getMsgSrc());
   }
   return replyMessage;
 }
예제 #3
0
 /**
  * Set the unique identifier of this message
  *
  * @param msgId message identifier
  */
 public void setMessageId(MessageId msgId) {
   if (msgId != null) {
     setMsgId(msgId.stringify());
   }
 }
예제 #4
0
 /**
  * Get the unique identifier of this message
  *
  * @return message identifier
  */
 public MessageId getMessageId() {
   return MessageId.from(getMsgId());
 }
예제 #5
0
 /**
  * Instantiate a message with a new id
  *
  * @param record a ZNRecord corresponding to a message
  * @param id unique message identifier
  */
 public Message(ZNRecord record, String id) {
   this(record, MessageId.from(id));
 }
예제 #6
0
 /**
  * Instantiate a message with a new id
  *
  * @param record a ZNRecord corresponding to a message
  * @param id unique message identifier
  */
 public Message(ZNRecord record, MessageId id) {
   super(new ZNRecord(record, id.stringify()));
   setMessageId(id);
 }
예제 #7
0
 /**
  * Instantiate a message
  *
  * @param type {@link MessageType} as a string or a custom message type
  * @param msgId unique message identifier
  */
 public Message(String type, String msgId) {
   this(type, MessageId.from(msgId));
 }