Exemplo 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);
            }
        }
Exemplo 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);
            }
        }