コード例 #1
0
        private void HandleMemberCollection(ICollection <IMember> initialMembers)
        {
            var prevMembers = new HashSet <IMember>();

            if (_members.Any())
            {
                prevMembers = new HashSet <IMember>(_members);
                _members.Clear();
            }
            foreach (var initialMember in initialMembers)
            {
                _members.Add(initialMember);
            }

            if (prevMembers.Count == 0)
            {
                //this means this is the first time client connected to cluster
                Logger.Info(MembersString());
                var immutableSetOfMembers = ImmutableSetOfMembers();
                var cluster = _client.GetCluster();
                var initialMembershipEvent = new InitialMembershipEvent(cluster, immutableSetOfMembers);
                _clusterService.HandleInitialMembershipEvent(initialMembershipEvent);
                _initialListFetched.Set();
                return;
            }
            var events = DetectMembershipEvents(prevMembers);

            Logger.Info(MembersString());
            FireMembershipEvent(events);
            _initialListFetched.Set();
        }
コード例 #2
0
 private void FireInitialMembershipEvent(InitialMembershipEvent @event)
 {
     foreach (var listener in _listeners.Values)
     {
         if (listener is IInitialMembershipListener)
         {
             ((IInitialMembershipListener)listener).Init(@event);
         }
     }
 }
コード例 #3
0
 private void InitMembershipListener()
 {
     foreach (var membershipListener in _listeners.Values)
     {
         if (membershipListener is IInitialMembershipListener)
         {
             // TODO: needs sync with membership events...
             var cluster = _client.GetCluster();
             var @event  = new InitialMembershipEvent(cluster, cluster.GetMembers());
             ((IInitialMembershipListener)membershipListener).Init(@event);
         }
     }
 }
コード例 #4
0
 internal void HandleInitialMembershipEvent(InitialMembershipEvent @event)
 {
     lock (_initialMembershipListenerMutex)
     {
         var initialMembers = @event.GetMembers();
         var newMap         = new Dictionary <Address, IMember>();
         foreach (var initialMember in initialMembers)
         {
             newMap.Add(initialMember.GetAddress(), initialMember);
         }
         _membersRef.Set(newMap);
         FireInitialMembershipEvent(@event);
     }
 }
コード例 #5
0
        private void ApplyInitialState(int version, ICollection <MemberInfo> memberInfos)
        {
            var snapshot = CreateSnapshot(version, memberInfos);

            _memberListSnapshot.Set(snapshot);
            Logger.Info(snapshot.ToString());
            var members = snapshot.Members.Values;
            var @event  = new InitialMembershipEvent(((IHazelcastInstance)_client).Cluster, members);

            foreach (var listener in _listeners.Values)
            {
                if (listener is IInitialMembershipListener initialMembershipListener)
                {
                    initialMembershipListener.Init(@event);
                }
            }
        }
コード例 #6
0
 private void InitMembershipListener(IMembershipListener listener)
 {
     if (listener is IInitialMembershipListener)
     {
         var cluster          = _client.GetCluster();
         var memberCollection = _membersRef.Get().Values;
         if (memberCollection.Count == 0)
         {
             //if members are empty,it means initial event did not arrive yet
             //it will be redirected to listeners when it arrives see #handleInitialMembershipEvent
             return;
         }
         var members = new HashSet <IMember>(memberCollection);
         var @event  = new InitialMembershipEvent(cluster, members);
         ((IInitialMembershipListener)listener).Init(@event);
     }
 }
コード例 #7
0
 public Guid AddMembershipListener(IMembershipListener listener)
 {
     CheckNotNull(listener, NullListenerIsNotAllowed);
     lock (_clusterViewLock)
     {
         var id = AddMembershipListenerWithoutInit(listener);
         if (listener is IInitialMembershipListener)
         {
             var cluster = ((IHazelcastInstance)_client).Cluster;
             var members = Members;
             //if members are empty,it means initial event did not arrive yet
             //it will be redirected to listeners when it arrives see #handleInitialMembershipEvent
             if (members.Count != 0)
             {
                 var @event = new InitialMembershipEvent(cluster, members);
                 ((IInitialMembershipListener)listener).Init(@event);
             }
         }
         return(id);
     }
 }
コード例 #8
0
 public void Init(InitialMembershipEvent membershipEvent)
 {
     _membershipEvent = membershipEvent;
     Interlocked.Increment(ref counter);
 }
コード例 #9
0
 public void Init(InitialMembershipEvent membershipEvent)
 {
     _membershipEvent = membershipEvent;
 }