Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public void Handle(PeerStarted message)
        {
            if (EnqueueIfRegistering(message))
            {
                return;
            }

            AddOrUpdatePeerEntry(message.PeerDescriptor);
            PeerUpdated?.Invoke(message.PeerDescriptor.Peer.Id, PeerUpdateAction.Started);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 public void Handle(PeerResponding message)
 {
     PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Updated);
 }
Esempio n. 9
0
 public void Handle(PeerSubscriptionsUpdated message)
 {
     PeerUpdated?.Invoke(message.PeerDescriptor.PeerId, PeerUpdateAction.Updated);
 }
Esempio n. 10
0
 public void Handle(PeerDecommissioned message)
 {
     PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Decommissioned);
 }
Esempio n. 11
0
 public void Handle(PeerStopped message)
 {
     PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Stopped);
 }