Ejemplo n.º 1
0
        /// <summary>
        /// Sends the given message to the specified endpoint.
        /// </summary>
        /// <param name="endpoint">The endpoint to which the message has to be send.</param>
        /// <param name="message">The message that has to be send.</param>
        /// <param name="maximumNumberOfRetries">The maximum number of times the endpoint will try to send the message if delivery fails.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="endpoint"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="EndpointNotContactableException">
        ///     Thrown if <paramref name="endpoint"/> has not provided any contact information.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="message"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="FailedToSendMessageException">
        ///     Thrown when the channel fails to deliver the message to the remote endpoint.
        /// </exception>
        public void SendMessageTo(EndpointId endpoint, ICommunicationMessage message, int maximumNumberOfRetries)
        {
            {
                Lokad.Enforce.Argument(() => endpoint);
                Lokad.Enforce.With <EndpointNotContactableException>(
                    m_Endpoints.CanCommunicateWithEndpoint(endpoint),
                    Resources.Exceptions_Messages_EndpointNotContactable_WithEndpoint,
                    endpoint);

                Lokad.Enforce.Argument(() => message);
            }

            var connection = RetrieveEndpointConnection(endpoint);

            if (connection == null)
            {
                throw new EndpointNotContactableException(endpoint);
            }

            SendMessageToUnregisteredEndpoint(connection, message, maximumNumberOfRetries);
        }
 private bool ShouldProcessMessage(ICommunicationMessage message)
 {
     return(m_Endpoints.CanCommunicateWithEndpoint(message.Sender) ||
            (message.IsHandshake() || IsMessageIndicatingEndpointDisconnect(message)));
 }