/// <summary>
        /// Disconnects from the given endpoint.
        /// </summary>
        /// <param name="id">The endpoint ID of the endpoint from which the current endpoint should disconnect.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        public void DisconnectFrom(EndpointId id)
        {
            {
                Lokad.Enforce.Argument(() => id);
            }

            m_EndpointStorage.TryRemoveEndpoint(id);
        }
Ejemplo n.º 2
0
        private void RemoveEndpoint(EndpointId sender)
        {
            if (m_EndpointApprovalState.ContainsKey(sender))
            {
                m_EndpointApprovalState.Remove(sender);
            }

            m_EndpointInformationStorage.TryRemoveEndpoint(sender);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Invokes the current action based on the provided message.
        /// </summary>
        /// <param name="message">The message upon which the action acts.</param>
        public void Invoke(ICommunicationMessage message)
        {
            var msg = message as EndpointDisconnectMessage;

            if (msg == null)
            {
                Debug.Assert(false, "The message is of the incorrect type.");
                return;
            }

            using (m_Diagnostics.Profiler.Measure(CommunicationConstants.TimingGroup, "Endpoint disconnecting"))
            {
                m_EndpointStorage.TryRemoveEndpoint(message.Sender);
            }
        }
Ejemplo n.º 4
0
        private void HandleKeepAliveIntervalOnElapsed(object sender, EventArgs e)
        {
            var now = m_Now();

            var maps = m_RegisteredConnections
                       .Where(p => p.Value.NextConnectionTime < now)
                       .Select(p => p.Value)
                       .ToList();

            object customData = null;

            if (m_KeepAliveCustomDataBuilder != null)
            {
                customData = m_KeepAliveCustomDataBuilder;
            }

            foreach (var map in maps)
            {
                var endpoint = map.Endpoint;
                try
                {
                    var response = m_VerifyConnectionTo(endpoint, m_MessageSendTimeout, customData);
                    response.ContinueWith(
                        t =>
                    {
                        ConnectionMap localMap;
                        if (!m_RegisteredConnections.TryGetValue(endpoint, out localMap))
                        {
                            return;
                        }

                        if ((t.Exception != null) || t.IsCanceled || t.IsFaulted)
                        {
                            // Timeout
                            // Comms failure
                            int count = ++localMap.NumberOfConnectionFailures;
                            if (count > m_MaximumNumberOfMissedKeepAliveSignals)
                            {
                                m_Endpoints.TryRemoveEndpoint(endpoint);
                            }

                            return;
                        }

                        localMap.NumberOfConnectionFailures = 0;
                        localMap.NextConnectionTime         = m_Now() + m_MaximumTimeBetweenConnectionConfirmations;

                        if (m_KeepAliveResponseDataHandler != null)
                        {
                            m_KeepAliveResponseDataHandler(t.Result);
                        }
                    },
                        TaskContinuationOptions.ExecuteSynchronously);
                }
                catch (Exception)
                {
                    map.NumberOfConnectionFailures += 1;
                }

                if (map.NumberOfConnectionFailures > m_MaximumNumberOfMissedKeepAliveSignals)
                {
                    m_Endpoints.TryRemoveEndpoint(endpoint);
                }
            }
        }