public class

DefaultMessagingService

extends Object
implements ClusterMessagingService
java.lang.Object
   ↳ org.apache.helix.messaging.DefaultMessagingService

Summary

Public Constructors
DefaultMessagingService(HelixManager manager)
Public Methods
Map<InstanceTypeList<Message>> generateMessage(Criteria recipientCriteria, Message message)
This will generate all messages to be sent given the recipientCriteria and MessageTemplate, the messages are not sent.
HelixTaskExecutor getExecutor()
synchronized void onConnected()
synchronized void registerMessageHandlerFactory(String type, MessageHandlerFactory factory)
This will register a message handler factory to create handlers for message.
int send(Criteria recipientCriteria, Message message, AsyncCallback callbackOnReply, int timeOut, int retryCount)
int send(Criteria recipientCriteria, Message message, AsyncCallback callbackOnReply, int timeOut)
This will send the message to all instances matching the criteria
When there is a reply to the message sent AsyncCallback.onReply will be invoked.
int send(Criteria recipientCriteria, Message messageTemplate)
Send message matching the specifications mentioned in recipientCriteria.
int sendAndWait(Criteria receipientCriteria, Message message, AsyncCallback asyncCallback, int timeOut, int retryCount)
int sendAndWait(Criteria recipientCriteria, Message message, AsyncCallback asyncCallback, int timeOut)
This will send the message to all instances matching the criteria
When there is a reply to the message sent AsynCallback.onReply will be invoked.
void sendNopMessage()
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.helix.ClusterMessagingService

Public Constructors

public DefaultMessagingService (HelixManager manager)

Public Methods

public Map<InstanceTypeList<Message>> generateMessage (Criteria recipientCriteria, Message message)

This will generate all messages to be sent given the recipientCriteria and MessageTemplate, the messages are not sent.

Parameters
message the Message on which to base the messages to send
Returns
  • messages to be sent, grouped by the type of instance to send the message to

public HelixTaskExecutor getExecutor ()

public synchronized void onConnected ()

public synchronized void registerMessageHandlerFactory (String type, MessageHandlerFactory factory)

This will register a message handler factory to create handlers for message. In case client code defines its own message type, it can define a message handler factory to create handlers to process those messages. Messages are processed in a threadpool which is hosted by cluster manager, and cluster manager will call the factory to create handler, and the handler is called in the threadpool. Note that only one message handler factory can be registered with one message type.

Parameters
type The message type that the factory will create handler for
factory The per-type message factory

public int send (Criteria recipientCriteria, Message message, AsyncCallback callbackOnReply, int timeOut, int retryCount)

public int send (Criteria recipientCriteria, Message message, AsyncCallback callbackOnReply, int timeOut)

This will send the message to all instances matching the criteria
When there is a reply to the message sent AsyncCallback.onReply will be invoked. Application can specify a timeout on AsyncCallback. After every reply is processed AsyncCallback.isDone will be invoked.
This method will return after sending the messages.
This is useful when message need to be sent and current thread need not wait for response since processing will be done in another thread.

Parameters
callbackOnReply callback to trigger on completion
timeOut Time to wait before failing the send
Returns
  • the number of messages that were successfully sent

public int send (Criteria recipientCriteria, Message messageTemplate)

Send message matching the specifications mentioned in recipientCriteria.

Parameters
messageTemplate message to be sent. Some attributes of this message will be changed as required
Returns
  • the number of messages that were successfully sent.

public int sendAndWait (Criteria receipientCriteria, Message message, AsyncCallback asyncCallback, int timeOut, int retryCount)

public int sendAndWait (Criteria recipientCriteria, Message message, AsyncCallback asyncCallback, int timeOut)

This will send the message to all instances matching the criteria
When there is a reply to the message sent AsynCallback.onReply will be invoked. Application can specify a timeout on AsyncCallback. After every reply is processed AsyncCallback.isDone will be invoked.
This method will return only after the AsyncCallback.isDone() returns true
This is useful when message need to be sent and current thread has to wait for response.
The current thread can use callbackOnReply instance to store application specific data.

Returns
  • the number of messages that were successfully sent

public void sendNopMessage ()