/// <summary> /// Send a message to another node, looking up the node containing the id. /// </summary> /// <param name="id">The id used to lookup the node to send the message to.</param> /// <param name="message">The message to send.</param> /// <returns>A value indicating whether the message was successfully sent.</returns> public MessageSendResult SendChordMessage(int id, string message) { var node = GetNodeContainingId(id); if (node == null) { var result = new MessageSendResult(); result.MessageSent(SendResults.SendingToSelfFailure); return result; } return SendMessage(node, message); }
/// <summary> /// Creates a message to be sent. /// </summary> /// <param name="destination">The destination of the message.</param> /// <param name="sender">The sender of the message.</param> /// <param name="type">The type of the message.</param> /// <param name="data">The data contained in the message.</param> /// <param name="result">The object to put the results in.</param> /// <param name="needsApprovedConnection">A value indicating whether the connection needs to have been approved.</param> /// <returns>A message to be sent.</returns> public static InternalMessage CreateSendMessage( NodeProperties destination, NodeProperties sender, MessageType type, string data, MessageSendResult result, bool needsApprovedConnection) { return new InternalMessage(destination, sender, type, data, false, null, result, null, needsApprovedConnection); }
/// <summary> /// Creates a message that is a response to another message. /// </summary> /// <param name="destination">The destination of the message.</param> /// <param name="sender">The sender of the message.</param> /// <param name="type">The type of the message.</param> /// <param name="data">The data contained in the message.</param> /// <param name="messageId">The id of the message.</param> /// <param name="result">The object to put the results in.</param> /// <returns>A message that is a response to another message.</returns> public static InternalMessage CreateResponseMessage( NodeProperties destination, NodeProperties sender, MessageType type, string data, uint messageId, MessageSendResult result) { return new InternalMessage(destination, sender, type, data, false, messageId, result, null, false); }
/// <summary> /// Initializes a new instance of the <see cref="InternalMessage" /> class. /// </summary> /// <param name="destination">The destination of the message.</param> /// <param name="sender">The sender of the message.</param> /// <param name="type">The type of message.</param> /// <param name="data">The data to go along with the message.</param> /// <param name="waitingForResponse">Whether this message is waiting for a response.</param> /// <param name="messageId">The id of the message if it has one.</param> /// <param name="sendResult">The result object passed back after sending a message.</param> /// <param name="responseResult"> /// The result object passed back after sending a message waiting for a response. /// </param> /// <param name="needsApprovedConnection">A value indicating whether the connection needs to have been approved.</param> /// <returns>The composed message to be sent over the wire to the receiving node.</returns> private InternalMessage(NodeProperties destination, NodeProperties sender, MessageType type, string data, bool waitingForResponse, uint? messageId, MessageSendResult sendResult, MessageResponseResult responseResult, bool needsApprovedConnection) { _destination = destination; _sender = sender; _type = type; _data = data; _waitingForResponse = waitingForResponse; _messageId = messageId; _sendResult = sendResult; _responseResult = responseResult; _needsApprovedConnection = needsApprovedConnection; }
/// <summary> /// Sends a response message to a node. /// </summary> /// <param name="responseTo">The message that this message is in response to.</param> /// <param name="type">The type of message to send.</param> /// <param name="message">The message to send.</param> /// <returns>A value indicating whether the message was successfully sent.</returns> protected MessageSendResult SendResponseInternal(Message responseTo, MessageType type, string message) { var result = new MessageSendResult(); var composedMessage = InternalMessage.CreateResponseMessage( responseTo.Sender, new NodeProperties("localhost", _port), type, message, responseTo.MessageId, result); lock (_messagesToSendLockObject) { _messagesToSend.Enqueue(composedMessage); } return result; }
/// <summary> /// Sends a message to a node. /// </summary> /// <param name="sendTo">The node to send the message to.</param> /// <param name="type">The type of message to send.</param> /// <param name="message">The message to send.</param> /// <param name="needsApprovedConnection"> /// A value indicating whether the connection needs to have been approved. /// </param> /// <returns>A value indicating whether the message was successfully sent.</returns> protected MessageSendResult SendMessageInternal(NodeProperties sendTo, MessageType type, string message, bool needsApprovedConnection) { var result = new MessageSendResult(); var composedMessage = InternalMessage.CreateSendMessage( sendTo, new NodeProperties("localhost", _port), type, message, result, needsApprovedConnection); lock (_messagesToSendLockObject) { _messagesToSend.Enqueue(composedMessage); } return result; }