org.apache.helix.model.Message类的使用及代码示例

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

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

Message介绍

[英]Messages sent internally among nodes in the system to respond to changes in state.
[中]在系统中的节点之间内部发送的消息,以响应状态的变化。

代码示例

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

@VisibleForTesting
void sendShutdownRequest() {
 Criteria criteria = new Criteria();
 criteria.setInstanceName("%");
 criteria.setResource("%");
 criteria.setPartition("%");
 criteria.setPartitionState("%");
 criteria.setRecipientInstanceType(InstanceType.CONTROLLER);
 criteria.setSessionSpecific(true);
 Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE,
   HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString());
 shutdownRequest.setMsgSubType(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString());
 shutdownRequest.setMsgState(Message.MessageState.NEW);
 shutdownRequest.setTgtSessionId("*");
 int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest);
 if (messagesSent == 0) {
  LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType()));
 }
}

代码示例来源: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/incubator-pinot

@Transition(from = "ONLINE", to = "OFFLINE")
public void onBecomeOfflineFromOnline(Message message, NotificationContext context) {
 _logger.info("SegmentOnlineOfflineStateModel.onBecomeOfflineFromOnline() : " + message);
 String tableNameWithType = message.getResourceName();
 String segmentName = message.getPartitionName();
 try {
  _instanceDataManager.removeSegment(tableNameWithType, segmentName);
 } catch (Exception e) {
  _logger.error("Caught exception in state transition from ONLINE -> OFFLINE for resource: {}, partition: {}",
    tableNameWithType, segmentName, e);
  Utils.rethrowException(e);
 }
}

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

/**
 * @param message The incoming message that has been received from helix.
 * @throws IllegalArgumentException if the message is not of right sub-type
 */
public SegmentRefreshMessage(final Message message) {
 super(message.getRecord());
 if (!message.getMsgSubType().equals(REFRESH_SEGMENT_MSG_SUB_TYPE)) {
  throw new IllegalArgumentException("Invalid message subtype:" + message.getMsgSubType());
 }
}

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

@Override
public MessageHandler createHandler(Message message, NotificationContext context) {
 String msgSubType = message.getMsgSubType();
 switch (msgSubType) {
  case TimeboundaryRefreshMessage.REFRESH_TIME_BOUNDARY_MSG_SUB_TYPE:
   LOGGER.info("time refresh msg received {} for table {}", message.getPartitionName());
   return new TimeboundaryRefreshMessageHandler(new TimeboundaryRefreshMessage(message), context);
  default:
   throw new UnsupportedOperationException("Unsupported user defined message sub type: " + msgSubType);
 }
}

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

private Message createStateTransitionMessage(HelixManager manager, Resource resource, String partitionName,
  String instanceName, String currentState, String nextState, String sessionId,
  String stateModelDefName) {
 String uuid = UUID.randomUUID().toString();
 Message message = new Message(MessageType.STATE_TRANSITION, uuid);
 message.setSrcName(manager.getInstanceName());
 message.setTgtName(instanceName);
 message.setMsgState(MessageState.NEW);
 message.setPartitionName(partitionName);
 message.setResourceName(resource.getResourceName());
 message.setFromState(currentState);
 message.setToState(nextState);
 message.setTgtSessionId(sessionId);
 message.setSrcSessionId(manager.getSessionId());
 message.setStateModelDef(stateModelDefName);
 message.setStateModelFactoryName(resource.getStateModelFactoryname());
 message.setBucketSize(resource.getBucketSize());
 if (resource.getResourceGroupName() != null) {
  message.setResourceGroupName(resource.getResourceGroupName());
 }
 if (resource.getResourceTag() != null) {
  message.setResourceTag(resource.getResourceTag());
 }
 return message;
}

代码示例来源: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

ClusterMessagingService messagingService = manager.getMessagingService();
Message requestBackupUriRequest =
  new Message(MessageType.USER_DEFINE_MSG, UUID.randomUUID().toString());
requestBackupUriRequest.setMsgSubType(BootstrapProcess.REQUEST_BOOTSTRAP_URL);
requestBackupUriRequest.setMsgState(MessageState.NEW);
Criteria recipientCriteria = new Criteria();
recipientCriteria.setInstanceName("*");
recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
recipientCriteria.setResource(message.getResourceName());
recipientCriteria.setPartition(message.getPartitionName());
recipientCriteria.setSessionSpecific(true);

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

Message newMessage = new Message(message.getRecord(), id);
String srcInstanceName = _manager.getInstanceName();
String tgtInstanceName = map.get("instanceName");
 continue;
newMessage.setSrcName(srcInstanceName);
newMessage.setTgtName(tgtInstanceName);
newMessage.setResourceName(map.get("resourceName"));
newMessage.setPartitionName(map.get("partitionName"));
if (recipientCriteria.isSessionSpecific()) {
 newMessage.setTgtSessionId(sessionIdMap.get(tgtInstanceName));

代码示例来源: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: apache/incubator-gobblin

@Override
public HelixTaskResult handleMessage() throws InterruptedException {
 LOGGER.warn(String
   .format("No handling setup for %s message of subtype: %s", Message.MessageType.USER_DEFINE_MSG.toString(),
     this._message.getMsgSubType()));
 final HelixTaskResult helixTaskResult = new HelixTaskResult();
 helixTaskResult.setSuccess(true);
 return helixTaskResult;
}

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

Message msg = new Message(factory.getMessageTypes().get(0), UUID.randomUUID().toString());
 msg.setTgtSessionId(manager.getSessionId());
 msg.setTgtName("Localhost_1123");
 msg.setSrcName("127.101.1.23_2234");
 msg.setCorrelationId(UUID.randomUUID().toString());
 msgList.add(msg);
Message exceptionMsg = new Message(factory.getMessageTypes().get(0), UUID.randomUUID().toString());
exceptionMsg.setTgtSessionId(manager.getSessionId());
exceptionMsg.setMsgSubType("EXCEPTION");
exceptionMsg.setTgtName("Localhost_1123");
exceptionMsg.setSrcName("127.101.1.23_2234");
exceptionMsg.setCorrelationId(UUID.randomUUID().toString());
msgList.add(exceptionMsg);
AssertJUnit.assertTrue(factory._handlersCreated == nMsgs1);
AssertJUnit.assertTrue(exceptionMsg.getMsgState() == MessageState.UNPROCESSABLE);
System.out.println("END TestCMTaskExecutor.testCreateHandlerException()");

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

@Test()
public void testOnBecomeOfflineFromStandby() {
 Message message = new Message(MessageType.STATE_TRANSITION, "0");
 message.setPartitionName(clusterName);
 message.setTgtName("controller_0");
 stateModel.onBecomeOfflineFromStandby(message, null);
}

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

public void onBecomeStandbyFromOffline(Message message, NotificationContext context) {
 System.out.println("LeaderStandbyStateModel.onBecomeStandbyFromOffline():" + _instanceName
   + " transitioning from " + message.getFromState() + " to " + message.getToState()
   + " for " + message.getResourceName() + " " + message.getPartitionName());
 sleep();
}

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

@Override public void doInject(ClusterDataCache cache) {
  String topStateNode = null;
  for (String instance : cfg.initialCurrentStates.keySet()) {
   if (cfg.initialCurrentStates.get(instance).currentState.equals("MASTER")) {
    topStateNode = instance;
    break;
   }
  }
  // Simulate the previous top state instance goes offline
  if (topStateNode != null) {
   long originalStartTime = cfg.currentStateWithMissingTopState.get(topStateNode).startTime;
   // Inject a message that fit expectedDuration
   Message message =
     new Message(Message.MessageType.STATE_TRANSITION, "thisisafakemessage");
   message.setTgtSessionId(SESSION_PREFIX + topStateNode.split("_")[1]);
   message.setToState("MASTER");
   message.setCreateTimeStamp(originalStartTime - messageTimeBeforeMasterless);
   message.setTgtName(topStateNode);
   message.setResourceName(TEST_RESOURCE);
   message.setPartitionName(PARTITION);
   cache.cacheMessages(Collections.singletonList(message));
  }
 }
}, 1, 0,

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

public void post(String zkServer, Message message, String clusterName, String instanceName) {
 ZkClient client = new ZkClient(zkServer);
 client.setZkSerializer(new ZNRecordSerializer());
 String path = PropertyPathBuilder.instanceMessage(clusterName, instanceName, message.getId());
 client.delete(path);
 ZNRecord record = client.readData(PropertyPathBuilder.liveInstance(clusterName, instanceName));
 message.setTgtSessionId(record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString()));
 message.setTgtName(record.getId());
 // System.out.println(message);
 client.createPersistent(path, message.getRecord());
}

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

@Test(enabled = false)
 @Override
 public void assertMessageReception(Message message) {
  Assert.assertEquals(message.getMsgType(), GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE);
  Assert.assertEquals(message.getMsgSubType(), HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString());
 }
}

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

public static Message createMessage(String msgId, String fromState, String toState,
  String tgtName, String resourceName, String partitionName) {
 Message msg = new Message(MessageType.STATE_TRANSITION, msgId);
 msg.setFromState(fromState);
 msg.setToState(toState);
 msg.setTgtName(tgtName);
 msg.setResourceName(resourceName);
 msg.setPartitionName(partitionName);
 msg.setStateModelDef("MasterSlave");
 return msg;
}

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

private static Message newMsg() {
  Message msg = new Message(DUMMY_MSG_TYPE, UUID.randomUUID().toString());
  msg.setTgtSessionId("*");
  msg.setTgtName("localhost_12918");
  return msg;
 }
}

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

protected Message createMessage(Message.MessageType type, String msgId, String fromState, String toState,
  String resourceName, String tgtName) {
 Message msg = new Message(type.toString(), msgId);
 msg.setFromState(fromState);
 msg.setToState(toState);
 msg.getRecord().setSimpleField(Message.Attributes.RESOURCE_NAME.toString(), resourceName);
 msg.setTgtName(tgtName);
 return msg;
}

相关文章