Java Code Examples for org.apache.helix.model.Message#hasRelayMessages()
The following examples show how to use
org.apache.helix.model.Message#hasRelayMessages() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelixTask.java From helix with Apache License 2.0 | 5 votes |
private void forwardRelayMessages(HelixDataAccessor accessor, Message message, long taskCompletionTime) { if (message.hasRelayMessages()) { Map<String, Message> relayMessages = message.getRelayMessages(); Builder keyBuilder = accessor.keyBuilder(); // Ignore all relay messages if participant's session has changed. if (!_manager.getSessionId().equals(message.getTgtSessionId())) { logger.info( "Session id has been changed, ignore all relay messages attached with " + message .getId()); return; } for (String instance : relayMessages.keySet()) { Message msg = relayMessages.get(instance); if (msg.getMsgSubType().equals(MessageType.RELAYED_MESSAGE.name())) { msg.setRelayTime(taskCompletionTime); if (msg.isExpired()) { logger.info( "Relay message expired, ignore " + msg.getId() + " to instance " + instance); continue; } PropertyKey msgKey = keyBuilder.message(instance, msg.getId()); boolean success = accessor.getBaseDataAccessor() .create(msgKey.getPath(), msg.getRecord(), AccessOption.PERSISTENT); if (!success) { logger.warn("Failed to send relay message " + msg.getId() + " to " + instance); } else { logger.info("Send relay message " + msg.getId() + " to " + instance); } } } } }
Example 2
Source File: InstanceMessagesCache.java From helix with Apache License 2.0 | 5 votes |
public void cacheMessages(Collection<Message> messages) { for (Message message : messages) { String instanceName = message.getTgtName(); if (!_messageCache.containsKey(instanceName)) { _messageCache.put(instanceName, Maps.<String, Message>newHashMap()); } _messageCache.get(instanceName).put(message.getId(), message); if (message.hasRelayMessages()) { for (Message relayMsg : message.getRelayMessages().values()) { cacheRelayMessage(relayMsg, message); } } } }
Example 3
Source File: MessageDispatchStage.java From helix with Apache License 2.0 | 4 votes |
protected List<Message> sendMessages(HelixDataAccessor dataAccessor, List<Message> messages) { List<Message> messageSent = new ArrayList<>(); if (messages == null || messages.isEmpty()) { return messageSent; } Builder keyBuilder = dataAccessor.keyBuilder(); List<PropertyKey> keys = new ArrayList<PropertyKey>(); for (Message message : messages) { LogUtil.logInfo( logger, _eventId, "Sending Message " + message.getMsgId() + " to " + message.getTgtName() + " transit " + message.getResourceName() + "." + message.getPartitionName() + "|" + message .getPartitionNames() + " from:" + message.getFromState() + " to:" + message .getToState() + ", relayMessages: " + message.getRelayMessages().size()); if (message.hasRelayMessages()) { for (Message msg : message.getRelayMessages().values()) { LogUtil.logInfo(logger, _eventId, "Sending Relay Message " + msg.getMsgId() + " to " + msg.getTgtName() + " transit " + msg.getResourceName() + "." + msg.getPartitionName() + "|" + msg .getPartitionNames() + " from:" + msg.getFromState() + " to:" + msg.getToState() + ", relayFrom: " + msg.getRelaySrcHost() + ", attached to message: " + message .getMsgId()); } } keys.add(keyBuilder.message(message.getTgtName(), message.getId())); } boolean[] results = dataAccessor.createChildren(keys, new ArrayList<>(messages)); for (int i = 0; i < results.length; i++) { if (!results[i]) { LogUtil.logError(logger, _eventId, "Failed to send message: " + keys.get(i)); } else { messageSent.add(messages.get(i)); } } return messageSent; }