示例#1
0
        /// <summary>
        /// Removes a subscriber that didn't respond to a heartbeat request
        /// </summary>
        /// <param name="sub"></param>
        void SubscriberTimedOut(Subscriber sub)
        {
            Debug.WriteLine("Not feeling a pulse for {0}", sub.SubscriberId);

            Storage.RemoveSubscriber(sub.SubscriberId);
            HeartbeatMonitorList.Remove(sub.SubscriberId);
        }
示例#2
0
        /// <summary>
        /// Interface method used by clients
        /// </summary>
        /// <param name="clientId">Calling clients' ID</param>
        public void Heartbeat(Guid clientId)
        {
            if (clientId == Guid.Empty)
            {
                return;
            }

            Debug.WriteLine("Received heartbeat from {0}", clientId);

            if (HeartbeatMonitorList.Contains(clientId))
            {
                HeartbeatMonitorList.Remove(clientId);
            }
            Storage.SubscriberSeen(clientId);
        }
示例#3
0
 /// <summary>
 /// Sends a heartbeat message to a given subscription
 /// </summary>
 /// <param name="sub">The subscription to ping</param>
 void SendHeartBeat(Subscriber sub)
 {
     if (!clients.ContainsKey(sub.SubscriberId))
     {
         clients.Add(sub.SubscriberId, ClientFactory.Connect(sub.Endpoint));
     }
     try
     {
         Debug.WriteLine("Checking {0} for a pulse", sub.SubscriberId);
         clients[sub.SubscriberId].Heartbeat();
         HeartbeatMonitorList.Add(sub.SubscriberId);
     }
     catch (EndpointNotFoundException)
     {
         Unsubscribe(sub.SubscriberId);
     }
 }
示例#4
0
        /// <summary>
        /// Send heartbeat messages to clients we haven't seen in a while
        /// </summary>
        void SendHeartBeat()
        {
            lock (lockHandle)
            {
                foreach (Subscriber sub in Storage.GetUnseenSubscribersSince(DateTime.Now - CheckHeartbeatAfter))
                {
                    if (HeartbeatMonitorList.Contains(sub.SubscriberId))
                    {
                        SubscriberTimedOut(sub);
                    }

                    else
                    {
                        SendHeartBeat(sub);
                    }
                }
            }
        }