Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo n.º 3
0
        public void Handle(PeerSubscriptionsUpdated message)
        {
            if (EnqueueIfRegistering(message))
            {
                return;
            }

            var peer = GetPeerCheckTimestamp(message.PeerDescriptor.Peer.Id, message.PeerDescriptor.TimestampUtc);

            if (peer == null)
            {
                return;
            }

            peer.SetSubscriptions(message.PeerDescriptor.Subscriptions ?? Enumerable.Empty <Subscription>(), message.PeerDescriptor.TimestampUtc);
            peer.TimestampUtc = message.PeerDescriptor.TimestampUtc ?? DateTime.UtcNow;

            PeerUpdated(message.PeerDescriptor.PeerId, PeerUpdateAction.Updated);
        }
Ejemplo n.º 4
0
 public void Handle(PeerSubscriptionsUpdated message)
 {
     PeerUpdated?.Invoke(message.PeerDescriptor.PeerId, PeerUpdateAction.Updated);
 }