org.apache.helix.model.Message.setMsgId()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.4k)|赞(0)|评价(0)|浏览(89)

本文整理了Java中org.apache.helix.model.Message.setMsgId()方法的一些代码示例,展示了Message.setMsgId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setMsgId()方法的具体详情如下:
包路径:org.apache.helix.model.Message
类名称:Message
方法名:setMsgId

Message.setMsgId介绍

[英]Set the unique identifier of this message
[中]设置此消息的唯一标识符

代码示例

代码示例来源:origin: apache/incubator-gobblin

private List<Message> generateMessagesForController(Message message) {
 List<Message> messages = new ArrayList<Message>();
 String id = UUID.randomUUID().toString();
 Message newMessage = new Message(message.getRecord(), id);
 newMessage.setMsgId(id);
 newMessage.setSrcName(_manager.getInstanceName());
 newMessage.setTgtName("Controller");
 messages.add(newMessage);
 return messages;
}

代码示例来源:origin: apache/helix

/**
 * 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) {
 super(new ZNRecord(record, id));
 setMsgId(id);
}

代码示例来源:origin: org.apache.helix/helix-core

/**
 * 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) {
 super(new ZNRecord(record, id));
 setMsgId(id);
}

代码示例来源:origin: apache/helix

/**
 * Instantiate a message with a new id
 * @param message message to be copied
 * @param id unique message identifier
 */
public Message(Message message, String id) {
 super(new ZNRecord(message.getRecord(), id));
 setMsgId(id);
}

代码示例来源:origin: org.apache.gobblin/gobblin-cluster

private List<Message> generateMessagesForController(Message message) {
 List<Message> messages = new ArrayList<Message>();
 String id = UUID.randomUUID().toString();
 Message newMessage = new Message(message.getRecord(), id);
 newMessage.setMsgId(id);
 newMessage.setSrcName(_manager.getInstanceName());
 newMessage.setTgtName("Controller");
 messages.add(newMessage);
 return messages;
}

代码示例来源:origin: com.linkedin.gobblin/gobblin-cluster

private List<Message> generateMessagesForController(Message message) {
 List<Message> messages = new ArrayList<Message>();
 String id = UUID.randomUUID().toString();
 Message newMessage = new Message(message.getRecord(), id);
 newMessage.setMsgId(id);
 newMessage.setSrcName(_manager.getInstanceName());
 newMessage.setTgtName("Controller");
 messages.add(newMessage);
 return messages;
}

代码示例来源:origin: org.apache.helix/helix-core

private List<Message> generateMessagesForController(Message message) {
 List<Message> messages = new ArrayList<Message>();
 String id = (message.getMsgId() == null) ? UUID.randomUUID().toString() : message.getMsgId();
 Message newMessage = new Message(message.getRecord(), id);
 newMessage.setMsgId(id);
 newMessage.setSrcName(_manager.getInstanceName());
 newMessage.setTgtName(InstanceType.CONTROLLER.name());
 messages.add(newMessage);
 return messages;
}

代码示例来源:origin: apache/helix

private List<Message> generateMessagesForController(Message message) {
 List<Message> messages = new ArrayList<Message>();
 String id = (message.getMsgId() == null) ? UUID.randomUUID().toString() : message.getMsgId();
 Message newMessage = new Message(message.getRecord(), id);
 newMessage.setMsgId(id);
 newMessage.setSrcName(_manager.getInstanceName());
 newMessage.setTgtName(InstanceType.CONTROLLER.name());
 messages.add(newMessage);
 return messages;
}

代码示例来源:origin: apache/helix

/**
 * 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) {
 super(new ZNRecord(msgId));
 _record.setSimpleField(Attributes.MSG_TYPE.toString(), type);
 setMsgId(msgId);
 setMsgState(MessageState.NEW);
 _record.setLongField(Attributes.CREATE_TIMESTAMP.toString(), new Date().getTime());
}

代码示例来源:origin: org.apache.helix/helix-core

/**
 * 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) {
 super(new ZNRecord(msgId));
 _record.setSimpleField(Attributes.MSG_TYPE.toString(), type);
 setMsgId(msgId);
 setMsgState(MessageState.NEW);
 _record.setLongField(Attributes.CREATE_TIMESTAMP.toString(), new Date().getTime());
}

代码示例来源:origin: apache/helix

private void syncSessionToController(HelixManager manager) {
 if (_lastSessionSyncTime == null ||
     System.currentTimeMillis() - _lastSessionSyncTime > SESSION_SYNC_INTERVAL) { // > delay since last sync
  HelixDataAccessor accessor = manager.getHelixDataAccessor();
  PropertyKey key = new Builder(manager.getClusterName()).controllerMessage(SESSION_SYNC);
  if (accessor.getProperty(key) == null) {
   LOG.info(String.format("Participant %s syncs session with controller", manager.getInstanceName()));
   Message msg = new Message(MessageType.PARTICIPANT_SESSION_CHANGE, SESSION_SYNC);
   msg.setSrcName(manager.getInstanceName());
   msg.setTgtSessionId("*");
   msg.setMsgState(MessageState.NEW);
   msg.setMsgId(SESSION_SYNC);
   Criteria cr = new Criteria();
   cr.setRecipientInstanceType(InstanceType.CONTROLLER);
   cr.setSessionSpecific(false);
   manager.getMessagingService().send(cr, msg);
   _lastSessionSyncTime = System.currentTimeMillis();
  }
 }
}

代码示例来源:origin: org.apache.helix/helix-core

private void syncSessionToController(HelixManager manager) {
 if (_lastSessionSyncTime == null ||
     System.currentTimeMillis() - _lastSessionSyncTime > SESSION_SYNC_INTERVAL) { // > delay since last sync
  HelixDataAccessor accessor = manager.getHelixDataAccessor();
  PropertyKey key = new Builder(manager.getClusterName()).controllerMessage(SESSION_SYNC);
  if (accessor.getProperty(key) == null) {
   LOG.info(String.format("Participant %s syncs session with controller", manager.getInstanceName()));
   Message msg = new Message(MessageType.PARTICIPANT_SESSION_CHANGE, SESSION_SYNC);
   msg.setSrcName(manager.getInstanceName());
   msg.setTgtSessionId("*");
   msg.setMsgState(MessageState.NEW);
   msg.setMsgId(SESSION_SYNC);
   Criteria cr = new Criteria();
   cr.setRecipientInstanceType(InstanceType.CONTROLLER);
   cr.setSessionSpecific(false);
   manager.getMessagingService().send(cr, msg);
   _lastSessionSyncTime = System.currentTimeMillis();
  }
 }
}

代码示例来源:origin: org.apache.helix/helix-core

public void postTestMessage(String zkServer, String clusterName, String instanceName) {
 String msgSrc = "cm-instance-0";
 String msgId = "TestMessageId-2";
 Message message = new Message(MessageType.STATE_TRANSITION, msgId);
 message.setMsgId(msgId);
 message.setSrcName(msgSrc);
 message.setTgtName(instanceName);
 message.setMsgState(MessageState.NEW);
 message.setFromState("Slave");
 message.setToState("Master");
 message.setPartitionName("EspressoDB.partition-0." + instanceName);
 post(zkServer, message, clusterName, instanceName);
}

代码示例来源:origin: apache/helix

public void postTestMessage(String zkServer, String clusterName, String instanceName) {
 String msgSrc = "cm-instance-0";
 String msgId = "TestMessageId-2";
 Message message = new Message(MessageType.STATE_TRANSITION, msgId);
 message.setMsgId(msgId);
 message.setSrcName(msgSrc);
 message.setTgtName(instanceName);
 message.setMsgState(MessageState.NEW);
 message.setFromState("Slave");
 message.setToState("Master");
 message.setPartitionName("EspressoDB.partition-0." + instanceName);
 post(zkServer, message, clusterName, instanceName);
}

代码示例来源:origin: apache/helix

void sendMessage(String msgId, String instanceName, String fromState, String toState,
  String partitionKey, int partitionId) throws InterruptedException, JsonGenerationException,
  JsonMappingException, IOException {
 Message message = new Message(MessageType.STATE_TRANSITION, msgId);
 message.setMsgId(msgId);
 message.setSrcName(srcName);
 message.setTgtName(instanceName);
 message.setMsgState(MessageState.NEW);
 message.setFromState(fromState);
 message.setToState(toState);
 // message.setPartitionId(partitionId);
 message.setPartitionName(partitionKey);
 String path = PropertyPathBuilder.instanceMessage(clusterName, instanceName, message.getId());
 ObjectMapper mapper = new ObjectMapper();
 StringWriter sw = new StringWriter();
 mapper.writeValueUsingView(sw, message, Message.class);
 System.out.println(sw.toString());
 client.delete(path);
 Thread.sleep(10000);
 ZNRecord record = client.readData(PropertyPathBuilder.liveInstance(clusterName, instanceName));
 message.setTgtSessionId(record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString())
   .toString());
 client.createPersistent(path, message);
}

代码示例来源:origin: apache/helix

@Test()
public void sendSelfMsg() {
 String hostSrc = "localhost_" + START_PORT;
 for (int i = 0; i < NODE_NR; i++) {
  TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
  String hostDest = "localhost_" + (START_PORT + i);
  _participants[i].getMessagingService().registerMessageHandlerFactory(
    factory.getMessageTypes(), factory);
 }
 String msgId = new UUID(123, 456).toString();
 Message msg = new Message(new TestMessagingHandlerFactory().getMessageTypes().get(0), msgId);
 msg.setMsgId(msgId);
 msg.setSrcName(hostSrc);
 msg.setTgtSessionId("*");
 msg.setMsgState(MessageState.NEW);
 String para = "Testing messaging para";
 msg.getRecord().setSimpleField("TestMessagingPara", para);
 Criteria cr = new Criteria();
 cr.setInstanceName("%");
 cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
 cr.setSessionSpecific(false);
 cr.setSelfExcluded(false);
 AsyncCallback callback1 = new MockAsyncCallback();
 int messageSent1 =
   _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);
 AssertJUnit.assertTrue(callback1.getMessageReplied().size() == NODE_NR);
 AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord()
   .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage")
   .equals("TestReplyMessage"));
}

代码示例来源:origin: apache/helix

msg.setMsgId(msgId);
msg.setSrcName(hostSrc);
msg.setTgtSessionId("*");

代码示例来源:origin: apache/helix

@Test()
public void TestBlockingSendReceive() throws Exception {
 String hostSrc = "localhost_" + START_PORT;
 String hostDest = "localhost_" + (START_PORT + 1);
 TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
 _participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageTypes(),
   factory);
 String msgId = new UUID(123, 456).toString();
 Message msg = new Message(factory.getMessageTypes().get(0), msgId);
 msg.setMsgId(msgId);
 msg.setSrcName(hostSrc);
 msg.setTgtSessionId("*");
 msg.setMsgState(MessageState.NEW);
 String para = "Testing messaging para";
 msg.getRecord().setSimpleField("TestMessagingPara", para);
 Criteria cr = new Criteria();
 cr.setInstanceName(hostDest);
 cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
 cr.setSessionSpecific(false);
 AsyncCallback asyncCallback = new MockAsyncCallback();
 int messagesSent =
   _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback, 60000);
 AssertJUnit.assertTrue(asyncCallback.getMessageReplied().get(0).getRecord()
   .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage")
   .equals("TestReplyMessage"));
 AssertJUnit.assertTrue(asyncCallback.getMessageReplied().size() == 1);
 AsyncCallback asyncCallback2 = new MockAsyncCallback();
 messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback2, 500);
 AssertJUnit.assertTrue(asyncCallback2.isTimedOut());
}

代码示例来源:origin: apache/helix

@Test()
public void TestBlockingSendReceive() {
 String hostDest = "localhost_" + (START_PORT + 1);
 TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
 _participants[1].getMessagingService()
   .registerMessageHandlerFactory(factory.getMessageTypes(), factory);
 String msgId = new UUID(123, 456).toString();
 Message msg = new Message(factory.getMessageTypes().get(0), msgId);
 msg.setMsgId(msgId);
 msg.setSrcName(_hostSrc);
 msg.setTgtSessionId("*");
 msg.setMsgState(MessageState.NEW);
 String para = "Testing messaging para";
 msg.getRecord().setSimpleField("TestMessagingPara", para);
 Criteria cr = new Criteria();
 cr.setInstanceName(hostDest);
 cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
 cr.setSessionSpecific(false);
 cr.setClusterName(CLUSTER_NAME);
 AsyncCallback asyncCallback = new MockAsyncCallback();
 int messagesSent =
   _adminController.getMessagingService().sendAndWait(cr, msg, asyncCallback, 60000);
 AssertJUnit.assertTrue(asyncCallback.getMessageReplied().get(0).getRecord()
   .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage")
   .equals("TestReplyMessage"));
 AssertJUnit.assertTrue(asyncCallback.getMessageReplied().size() == 1);
 AsyncCallback asyncCallback2 = new MockAsyncCallback();
 messagesSent = _adminController.getMessagingService().sendAndWait(cr, msg, asyncCallback2, 500);
 AssertJUnit.assertTrue(asyncCallback2.isTimedOut());
}

代码示例来源:origin: apache/helix

msg.setMsgId(msgId);
msg.setSrcName(_hostSrc);
msg.setTgtSessionId("*");

相关文章