Пример #1
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);
        }
Пример #2
0
 public void Handle(PeerStopped message)
 {
     PeerUpdated?.Invoke(message.PeerId, PeerUpdateAction.Stopped);
 }
Пример #3
0
        public void should_handle_directory_events_during_the_register()
        {
            var otherPeerDescriptor = _otherPeer.ToPeerDescriptor(true, typeof(FakeCommand), typeof(FakeEvent));
            otherPeerDescriptor.TimestampUtc = default(DateTime);
            var peerStarted = new PeerStarted(otherPeerDescriptor);
            var peerStopped = new PeerStopped(_otherPeer);

            _bus.AddHandler<RegisterPeerCommand>(x =>
            {
                var peerDescriptor = _otherPeer.ToPeerDescriptor(true);
                _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow.AddTicks(1), new MessageTypeId(typeof(FakeEvent)), BindingKey.Empty));
                return new RegisterPeerResponse(new[] { peerDescriptor });
            });

            var task = Task.Run(() =>
            {
                for (var i = 0; i < 10000; i++)
                {
                    _directory.Handle(peerStarted);
                    _directory.Handle(peerStopped);
                }
            });

            Wait.Until(() => task.Status == TaskStatus.Running || task.Status == TaskStatus.RanToCompletion, 1.Second());

           _directory.Register(_bus, _self, otherPeerDescriptor.Subscriptions );

            task.Wait(1.Second());
        }