public bool TryDequeueNode(out SwimNode node) { lock (_nodesLock) { return(Nodes.TryDequeue(out node)); } }
public void AddNode(SwimNode node) { lock (_nodesLock) { if (!Nodes.Any(x => x.Endpoint == node.Endpoint)) { Nodes.Enqueue(node); } } }
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); } }
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(); }
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); } }