public ClientHolderState(Lazy <ZooKeeperNetExClient> client, ConnectionWatcher connectionWatcher, ConnectionState connectionState, string connectionString) { LazyClient = client; ConnectionState = connectionState; ConnectionString = connectionString; ConnectionWatcher = connectionWatcher; }
private bool ResetClient([NotNull] ClientHolderState currentState) { log.Info("Resetting client. Current state: '{CurrentState}'.", currentState); var newConnectionString = settings.ConnectionStringProvider(); if (string.IsNullOrEmpty(newConnectionString)) { log.Error("Failed to resolve any ZooKeeper replicas."); return(false); } var newConnectionWatcher = new ConnectionWatcher(ProcessEvent); var newClient = new Lazy <ZooKeeperNetExClient>( () => { using (ExecutionContext.SuppressFlow()) { return(new ZooKeeperNetExClient( newConnectionString, settings.ToInnerConnectionTimeout(), newConnectionWatcher, settings.CanBeReadOnly)); } }, LazyThreadSafetyMode.ExecutionAndPublication); var suspendedFor = suspendedManager.GetNextDelay(); var newState = suspendedFor != null && !currentState.IsSuspended ? ClientHolderState.CreateSuspended(suspendedFor) : ClientHolderState.CreateActive(newClient, newConnectionWatcher, ConnectionState.Disconnected, newConnectionString, settings); if (ChangeState(currentState, newState)) { newState.Client?.Touch(); // Note(kungurtsev): increase delay for each active (not suspended) client creation. if (!currentState.IsSuspended) { suspendedManager.IncreaseDelay(); } currentState.Dispose(); } return(true); }
private bool ResetClient([NotNull] ClientHolderState currentState) { log.Info("Resetting client. Current state: '{CurrentState}'.", currentState); var newConnectionString = settings.ConnectionStringProvider(); if (string.IsNullOrEmpty(newConnectionString)) { log.Error("Failed to resolve any ZooKeeper replicas."); return(false); } var newConnectionWatcher = new ConnectionWatcher(ProcessEvent); var newClient = new Lazy <ZooKeeperNetExClient>( () => { using (ExecutionContext.SuppressFlow()) { return(new ZooKeeperNetExClient( newConnectionString, settings.ToInnerConnectionTimeout(), newConnectionWatcher, settings.CanBeReadOnly)); } }, LazyThreadSafetyMode.ExecutionAndPublication); var newState = new ClientHolderState(newClient, newConnectionWatcher, ConnectionState.Disconnected, newConnectionString); if (ChangeState(currentState, newState)) { newState.Client?.Touch(); currentState.Dispose(); } return(true); }
public ConnectionEvent(WatchedEvent @event, ConnectionWatcher eventFrom) { Event = @event; EventFrom = eventFrom; }