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); }
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); }
private void FireMembershipEvent(MembershipEvent @event) { foreach (var listener in _listeners.Values) { if (@event.GetEventType() == MembershipEvent.MemberAdded) { listener.MemberAdded(@event); } else { listener.MemberRemoved(@event); } } }
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); } } })); }
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); } }