use of org.apache.helix.model.Message in project helix by apache.
the class MessageTimeoutTask method run.
@Override
public void run() {
Message message = _task.getMessage();
// NotificationContext context = _task.getNotificationContext();
// System.out.println("msg: " + message.getMsgId() + " timeouot.");
LOG.warn("Message time out, canceling. id:" + message.getMsgId() + " timeout : " + message.getExecutionTimeout());
_task.onTimeout();
_executor.cancelTask(_task);
}
use of org.apache.helix.model.Message in project helix by apache.
the class DefaultMessagingService method sendNopMessageInternal.
private void sendNopMessageInternal() {
try {
Message nopMsg = new Message(MessageType.NO_OP, UUID.randomUUID().toString());
nopMsg.setSrcName(_manager.getInstanceName());
HelixDataAccessor accessor = _manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
if (_manager.getInstanceType() == InstanceType.CONTROLLER || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) {
nopMsg.setTgtName(InstanceType.CONTROLLER.name());
accessor.setProperty(keyBuilder.controllerMessage(nopMsg.getId()), nopMsg);
}
if (_manager.getInstanceType() == InstanceType.PARTICIPANT || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) {
nopMsg.setTgtName(_manager.getInstanceName());
accessor.setProperty(keyBuilder.message(nopMsg.getTgtName(), nopMsg.getId()), nopMsg);
}
} catch (Exception e) {
_logger.error(e.toString());
}
}
use of org.apache.helix.model.Message in project helix by apache.
the class DefaultMessagingService method generateMessage.
public Map<InstanceType, List<Message>> generateMessage(final Criteria recipientCriteria, final Message message) {
Map<InstanceType, List<Message>> messagesToSendMap = new HashMap<InstanceType, List<Message>>();
InstanceType instanceType = recipientCriteria.getRecipientInstanceType();
if (instanceType == InstanceType.CONTROLLER) {
List<Message> messages = generateMessagesForController(message);
messagesToSendMap.put(InstanceType.CONTROLLER, messages);
// _dataAccessor.setControllerProperty(PropertyType.MESSAGES,
// newMessage.getRecord(), CreateMode.PERSISTENT);
} else if (instanceType == InstanceType.PARTICIPANT) {
List<Message> messages = new ArrayList<Message>();
List<Map<String, String>> matchedList = _evaluator.evaluateCriteria(recipientCriteria, _manager);
if (!matchedList.isEmpty()) {
Map<String, String> sessionIdMap = new HashMap<String, String>();
if (recipientCriteria.isSessionSpecific()) {
HelixDataAccessor accessor = _manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
List<LiveInstance> liveInstances = accessor.getChildValues(keyBuilder.liveInstances());
for (LiveInstance liveInstance : liveInstances) {
sessionIdMap.put(liveInstance.getInstanceName(), liveInstance.getSessionId());
}
}
for (Map<String, String> map : matchedList) {
String id = UUID.randomUUID().toString();
Message newMessage = new Message(message.getRecord(), id);
String srcInstanceName = _manager.getInstanceName();
String tgtInstanceName = map.get("instanceName");
// Don't send message to self
if (recipientCriteria.isSelfExcluded() && srcInstanceName.equalsIgnoreCase(tgtInstanceName)) {
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));
}
messages.add(newMessage);
}
messagesToSendMap.put(InstanceType.PARTICIPANT, messages);
}
}
return messagesToSendMap;
}
use of org.apache.helix.model.Message in project helix by apache.
the class DefaultMessagingService method generateMessagesForController.
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;
}
use of org.apache.helix.model.Message in project helix by apache.
the class BatchMessageHandler method createMsgHandlers.
List<MessageHandler> createMsgHandlers(List<Message> msgs, NotificationContext context) {
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
for (Message msg : msgs) {
MessageHandler handler = _msgHandlerFty.createHandler(msg, context);
handlers.add(handler);
}
return handlers;
}
Aggregations