public string AddMembershipListener(IMembershipListener listener) { if (listener == null) { throw new ArgumentNullException("listener"); } var id = Guid.NewGuid().ToString(); _listeners[id] = listener; if (listener is IInitialMembershipListener) { // TODO: needs sync with membership events... var cluster = _client.GetCluster(); ((IInitialMembershipListener)listener).Init(new InitialMembershipEvent(cluster, cluster.GetMembers())); } return(id); }
public void HandleMemberAttributeChange(string uuid, string key, int operationType, string value) { var memberMap = _clusterService.GetMembersRef(); if (memberMap == null) { return; } foreach (var target in memberMap.Values) { if (target.GetUuid().Equals(uuid)) { var type = (MemberAttributeOperationType)operationType; ((Member)target).UpdateAttribute(type, key, value); var memberAttributeEvent = new MemberAttributeEvent(_client.GetCluster(), target, type, key, value); _clusterService.FireMemberAttributeEvent(memberAttributeEvent); break; } } }
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); } }