Esempio n. 1
0
        public void EndProtocolPeriod()
        {
            try
            {
                Debug.WriteLine("Ending Protocol Period");
                Logger.LogInformation("Ending Protocol Period");

                lock (_receivedAckLock)
                {
                    if (ActiveNode != null)
                    {
                        if (!ReceivedAck)
                        {
                            Debug.WriteLine($"No response from Node {ActiveNode.Endpoint}, marking as dead.");
                            Logger.LogInformation($"No response from Node {ActiveNode.Endpoint}, marking as dead.");

                            AddBroadcastMessage(new DeadMessage(ActiveNode));
                        }
                        else
                        {
                            Debug.WriteLine($"Response from Node {ActiveNode.Endpoint}, marking as alive.");
                            Logger.LogInformation($"Response from Node {ActiveNode.Endpoint}, marking as alive.");

                            //  Add the node back into the queue.
                            AddNode(ActiveNode);
                        }

                        ActiveNode = null;

                        ProtocolPeriodsComplete++;

                        if (InitialNodeCount == ProtocolPeriodsComplete)
                        {
                            Debug.WriteLine("Shuffing Nodes");
                            Logger.LogInformation("Shuffing Nodes");

                            ShuffleNodes();

                            lock (_nodesLock)
                            {
                                InitialNodeCount = Nodes.Count;
                            }

                            ProtocolPeriodsComplete = 0;
                        }
                    }

                    ReceivedAck = false;
                    ProtocolTimer.Stop();
                    ProtocolTimerRunning = false;
                    PingTimer.Stop();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"{e.ToString()}: {e.StackTrace}");
                Logger.LogError(e, string.Empty);
            }
        }
Esempio n. 2
0
        public async Task BeginProtocolPeriodAsync()
        {
            try
            {
                Debug.WriteLine("Beginning Protocol Period");
                Logger.LogInformation("Beginning Protocol Period");

                ProtocolTimer.Start();

                ProtocolTimerRunning = true;

                lock (_receivedAckLock)
                {
                    ReceivedAck = false;

                    SwimNode node = null;

                    lock (_nodesLock)
                    {
                        InitialNodeCount = Nodes.Count;

                        if (Nodes.TryDequeue(out node))
                        {
                            ActiveNode = node;

                            Debug.WriteLine(ActiveNode.Endpoint);

                            PingNode(ActiveNode);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"{e.ToString()}: {e.StackTrace}");
                Logger.LogError(e, string.Empty);
            }
        }