internal void ListenMembershipEvents(Address ownerConnectionAddress) { if (Logger.IsFinestEnabled()) { Logger.Finest("Starting to listen for membership events from " + ownerConnectionAddress); } _initialListFetched = new ManualResetEventSlim(); try { var clientMessage = ClientAddMembershipListenerCodec.EncodeRequest(false); DistributedEventHandler handler = m => ClientAddMembershipListenerCodec.EventHandler .HandleEvent(m, HandleMember, HandleMemberCollection, HandleMemberAttributeChange); try { var connection = _connectionManager.GetConnection(ownerConnectionAddress); if (connection == null) { throw new InvalidOperationException( "Can not load initial members list because owner connection is null. Address " + ownerConnectionAddress); } var invocationService = (ClientInvocationService)_client.GetInvocationService(); var future = invocationService.InvokeListenerOnConnection(clientMessage, handler, connection); var response = ThreadUtil.GetResult(future); //registration id is ignored as this listener will never be removed var registirationId = ClientAddMembershipListenerCodec.DecodeResponse(response).response; WaitInitialMemberListFetched(); } catch (Exception e) { throw ExceptionUtil.Rethrow(e); } } catch (Exception e) { if (_client.GetLifecycleService().IsRunning()) { if (Logger.IsFinestEnabled()) { Logger.Warning("Error while registering to cluster events! -> " + ownerConnectionAddress, e); } else { Logger.Warning("Error while registering to cluster events! -> " + ownerConnectionAddress + ", Error: " + e); } } } }
private void EnsureOwnerConnectionAvailable() { var clientClusterService = _client.GetClientClusterService(); var ownerConnectionAddress = clientClusterService.GetOwnerConnectionAddress(); var isOwnerConnectionAvailable = ownerConnectionAddress != null && _clientConnectionManager.GetConnection(ownerConnectionAddress) != null; if (!isOwnerConnectionAvailable) { if (_isShutDown) { throw new HazelcastException("Client is shut down."); } throw new IOException("Owner connection was not live."); } }