示例#1
0
 public bool TryDequeueNode(out SwimNode node)
 {
     lock (_nodesLock)
     {
         return(Nodes.TryDequeue(out node));
     }
 }
示例#2
0
 public void AddNode(SwimNode node)
 {
     lock (_nodesLock)
     {
         if (!Nodes.Any(x => x.Endpoint == node.Endpoint))
         {
             Nodes.Enqueue(node);
         }
     }
 }
示例#3
0
 public void RemoveNode(SwimNode node)
 {
     //  This is a main reason why we need to lock the nodes collection,
     //  when nodes die we need to remove them from our queue.
     //  TODO: Implement a more robust collection.
     lock (_nodesLock)
     {
         var nodes_filtered = Nodes.Where(x => x.Endpoint != node.Endpoint);
         Nodes = new ConcurrentQueue <SwimNode>(nodes_filtered);
     }
 }
示例#4
0
        private void PingNode(SwimNode node)
        {
            //  Ping node directly

            PingCorrelationId = Ulid.NewUlid();

            Debug.WriteLine($"Pinging node {node.Endpoint}.");
            Logger.LogInformation($"Pinging node {node.Endpoint}.");

            ProtocolProvider.SendMessage(node, new PingMessage(PingCorrelationId.Value)
            {
                SourceNode = ProtocolProvider.Node
            });

            PingTimer.Start();
        }
示例#5
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);
            }
        }