/// <summary>
        /// Sends a message to another node, looking up the node containing the id, and awaits a response.
        /// </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 response object that contains whether the message was successfully sent and the
        /// response from the receiver.
        /// </returns>
        public MessageResponseResult SendChordMessageResponse(int id, string message)
        {
            var node = GetNodeContainingId(id);
            if (node == null)
            {
                var result = new MessageResponseResult();
                result.MessageSent(SendResults.SendingToSelfFailure);
                return result;
            }

            return SendMessageResponse(node, message);
        }
 /// <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>
 /// Creates a message to be sent and that is expecting a response.
 /// </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>
 /// <param name="needsApprovedConnection">A value indicating whether the connection needs to have been approved.</param>
 /// <returns>A message to be sent and that is expecting a response.</returns>
 public static InternalMessage CreateSendResponseMessage(
     NodeProperties destination,
     NodeProperties sender,
     MessageType type,
     string data,
     uint messageId,
     MessageResponseResult result,
     bool needsApprovedConnection)
 {
     return new InternalMessage(destination, sender, type, data, true, messageId, null, result, needsApprovedConnection);
 }
Example #4
0
        /// <summary>
        /// Sends a message to a node and awaits a response.
        /// </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 MessageResponseResult SendMessageResponseInternal(NodeProperties sendTo, MessageType type, string message, bool needsApprovedConnection)
        {
            uint id = (uint)Interlocked.Increment(ref _messageIdCounter);
            lock (_responsesLockObject)
            {
                _responses[id] = null;
            }

            var result = new MessageResponseResult();
            var composedMessage = InternalMessage.CreateSendResponseMessage(
                sendTo,
                new NodeProperties("localhost", _port),
                type,
                message,
                id,
                result,
                needsApprovedConnection);

            lock (_messagesToSendLockObject)
            {
                _messagesToSend.Enqueue(composedMessage);
            }

            return result;
        }