public void Handle(PeerSubscriptionsForTypesUpdated message) { if (EnqueueIfRegistering(message)) { return; } var peer = GetPeerCheckTimestamp(message.PeerId, message.TimestampUtc); if (peer.Value == null) { WarnWhenPeerDoesNotExist(peer, message.PeerId); return; } var subscriptionsForTypes = message.SubscriptionsForType ?? Array.Empty <SubscriptionsForType>(); peer.Value.SetSubscriptionsForType(subscriptionsForTypes, message.TimestampUtc); PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Updated); var observedSubscriptions = GetObservedSubscriptions(subscriptionsForTypes); if (observedSubscriptions.Count > 0) { PeerSubscriptionsUpdated?.Invoke(message.PeerId, observedSubscriptions); } }
private void AddOrUpdatePeerEntry(PeerDescriptor peerDescriptor, bool shouldRaisePeerUpdated) { var subscriptions = peerDescriptor.Subscriptions ?? Array.Empty <Subscription>(); var peerEntry = _peers.AddOrUpdate(peerDescriptor.PeerId, key => CreatePeerEntry(), (key, entry) => UpdatePeerEntry(entry)); peerEntry.SetSubscriptions(subscriptions, peerDescriptor.TimestampUtc); if (shouldRaisePeerUpdated) { PeerUpdated?.Invoke(peerDescriptor.Peer.Id, PeerUpdateAction.Started); } var observedSubscriptions = GetObservedSubscriptions(subscriptions); if (observedSubscriptions.Count > 0) { PeerSubscriptionsUpdated?.Invoke(peerDescriptor.PeerId, observedSubscriptions); } PeerEntry CreatePeerEntry() => new PeerEntry(peerDescriptor, _globalSubscriptionsIndex); PeerEntry UpdatePeerEntry(PeerEntry entry) { entry.Peer.EndPoint = peerDescriptor.Peer.EndPoint; entry.Peer.IsUp = peerDescriptor.Peer.IsUp; entry.Peer.IsResponding = peerDescriptor.Peer.IsResponding; entry.IsPersistent = peerDescriptor.IsPersistent; entry.TimestampUtc = peerDescriptor.TimestampUtc ?? DateTime.UtcNow; entry.HasDebuggerAttached = peerDescriptor.HasDebuggerAttached; return(entry); } }
public void Handle(PeerStarted message) { if (EnqueueIfRegistering(message)) { return; } AddOrUpdatePeerEntry(message.PeerDescriptor); PeerUpdated?.Invoke(message.PeerDescriptor.Peer.Id, PeerUpdateAction.Started); }
private void HandlePeerRespondingChange(PeerId peerId, bool isResponding) { var peer = _peers.GetValueOrDefault(peerId); if (peer == null) { return; } peer.Peer.IsResponding = isResponding; PeerUpdated?.Invoke(peerId, PeerUpdateAction.Updated); }
public void Handle(PeerDecommissioned message) { if (EnqueueIfRegistering(message)) { return; } if (!_peers.TryRemove(message.PeerId, out var removedPeer)) { return; } removedPeer.RemoveSubscriptions(); PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Decommissioned); }
public void Handle(PeerSubscriptionsForTypesUpdated message) { if (EnqueueIfRegistering(message)) { return; } var peer = GetPeerCheckTimestamp(message.PeerId, message.TimestampUtc); if (peer.Value == null) { WarnWhenPeerDoesNotExist(peer, message.PeerId); return; } peer.Value.SetSubscriptionsForType(message.SubscriptionsForType ?? Enumerable.Empty <SubscriptionsForType>(), message.TimestampUtc); PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Updated); }
public void Handle(PeerStopped message) { if (EnqueueIfRegistering(message)) { return; } var peer = GetPeerCheckTimestamp(message.PeerId, message.TimestampUtc); if (peer.Value == null) { return; } peer.Value.Peer.IsUp = false; peer.Value.Peer.IsResponding = false; peer.Value.TimestampUtc = message.TimestampUtc ?? DateTime.UtcNow; PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Stopped); }
public void Handle(PeerResponding message) { PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Updated); }
public void Handle(PeerSubscriptionsUpdated message) { PeerUpdated?.Invoke(message.PeerDescriptor.PeerId, PeerUpdateAction.Updated); }
public void Handle(PeerDecommissioned message) { PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Decommissioned); }
public void Handle(PeerStopped message) { PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Stopped); }