コード例 #1
0
        public void MemberRemovedEvent()
        {
            var reset = new ManualResetEventSlim();

            _client.GetCluster().AddMembershipListener(new MembershipListener
            {
                OnMemberAdded = memberAddedEvent => { reset.Set(); }
            });
            var member = StartMember(_remoteController, _cluster);

            Assert.IsTrue(reset.Wait(30 * 1000));
            reset.Reset();

            MembershipEvent memberRemovedEvent = null;

            _client.GetCluster().AddMembershipListener(new MembershipListener
            {
                OnMemberRemoved = memberRemoved =>
                {
                    memberRemovedEvent = memberRemoved;
                    reset.Set();
                }
            });
            StopMember(_remoteController, _cluster, member);

            Assert.IsTrue(reset.Wait(30 * 1000));
            Assert.IsInstanceOf <ICluster>(memberRemovedEvent.Source);
            Assert.IsInstanceOf <ICluster>(memberRemovedEvent.GetCluster());
            Assert.AreEqual(MembershipEvent.MemberRemoved, memberRemovedEvent.GetEventType());
            Assert.IsNotNull(memberRemovedEvent.GetMember());
            Assert.AreEqual(1, memberRemovedEvent.GetMembers().Count);
        }
コード例 #2
0
        public void MemberRemovedEvent()
        {
            var node = Cluster.AddNode();

            Client.GetCluster().AddMembershipListener(new MembershipListener
            {
                OnMemberAdded = memberAddedEvent => { Cluster.RemoveNode(node); }
            });

            var reset = new ManualResetEventSlim();

            MembershipEvent memberRemovedEvent = null;

            Client.GetCluster().AddMembershipListener(new MembershipListener
            {
                OnMemberRemoved = memberRemoved =>
                {
                    memberRemovedEvent = memberRemoved;
                    reset.Set();
                }
            });
            Assert.IsTrue(reset.Wait(30 * 1000));
            Assert.IsInstanceOf <ICluster>(memberRemovedEvent.Source);
            Assert.IsInstanceOf <ICluster>(memberRemovedEvent.GetCluster());
            Assert.AreEqual(MembershipEvent.MemberRemoved, memberRemovedEvent.GetEventType());
            Assert.IsNotNull(memberRemovedEvent.GetMember());
            Assert.AreEqual(1, memberRemovedEvent.GetMembers().Count);
        }
コード例 #3
0
 private void FireMembershipEvent(MembershipEvent @event)
 {
     foreach (var listener in _listeners.Values)
     {
         if (@event.GetEventType() == MembershipEvent.MemberAdded)
         {
             listener.MemberAdded(@event);
         }
         else
         {
             listener.MemberRemoved(@event);
         }
     }
 }
コード例 #4
0
 internal virtual void FireMembershipEvent(MembershipEvent @event)
 {
     _client.GetClientExecutionService().Submit((() =>
     {
         foreach (var listener in _listeners.Values)
         {
             if (@event.GetEventType() == MembershipEvent.MemberAdded)
             {
                 listener.MemberAdded(@event);
             }
             else
             {
                 listener.MemberRemoved(@event);
             }
         }
     }));
 }
コード例 #5
0
 internal void HandleMembershipEvent(MembershipEvent @event)
 {
     lock (_initialMembershipListenerMutex)
     {
         var member     = @event.GetMember();
         var dictionary = _membersRef.Get();
         var newMap     = new Dictionary <Address, IMember>(dictionary);
         if (@event.GetEventType() == MembershipEvent.MemberAdded)
         {
             newMap.Add(member.GetAddress(), member);
         }
         else
         {
             newMap.Remove(member.GetAddress());
         }
         _membersRef.Set(newMap);
         FireMembershipEvent(@event);
     }
 }