IMessageSender

The message sender is the service that can send messages. There are also methods for sending messages in targets, but these also use the message sender internally.

The message sender is available as a service via the service registry.

final IMessageSender messageSender = CServiceRegistry.getInstance()
                                                     .getService(IMessageSender.class);

Send messages

The methods for sending messages are always executed in pairs. While one method receives a complete message, the second method always receives the components of the message.

void send(@NotNull CMessage aMsg) throws CException;
void send(@NotNull CEnvelope aEnvelope,
          @NotNull CRecord aRecord) throws CException;

Send requests

If you want to receive a response to the message, you should set the corresponding flag in the envelope. By default, this flag is not set. These methods set the flag before the message is sent.

void sendRequest(@NotNull CEnvelope aEnvelope,
                 @NotNull CRecord aRecord) throws CException;
void sendRequest(@NotNull CMessage aMsg) throws CException;

Send notifications

If a response is not needed, the following methods can be used. You set the flag wantAnswer to false. By the way, in case of an error, replies are sent anyway. The error code and possibly an error text can then be taken from the response.

void sendNotification(@NotNull CMessage aMsg) throws CException;
void sendNotification(@NotNull CEnvelope aEnvelope,
                          @NotNull CRecord aRecord) throws CException;

Manually send back messages

Normally, messages are returned to the sender by the system if this is desired or in case of an error. However, if a message is put on hold the message can be returned manually after complete asynchronous processing.

void sendBack(@NotNull CMessage aMsg) throws CException;
void sendBack(@NotNull CEnvelope aEnvelope,
              @NotNull CRecord aRecord) throws CException;

Convenience methods

The node address of the own node can be determined via the message sender:

@NotNull CNodeAddress getNodeAddress();

A given node address can be checked to see if it matches that of the local node.

boolean isLocal(@NotNull CNodeAddress aNode);