private bool TryRecoverConnectionDelegate() { try { IFrameHandler fh = _endpoints.SelectOne(_factory.CreateFrameHandler); _delegate = new Connection(_factory, false, fh, ClientProvidedName); return(true); } catch (Exception e) { ESLog.Error("Connection recovery exception.", e); // Trigger recovery error events foreach (EventHandler <ConnectionRecoveryErrorEventArgs> h in ConnectionRecoveryError?.GetInvocationList() ?? Array.Empty <Delegate>()) { try { h(this, new ConnectionRecoveryErrorEventArgs(e)); } catch (Exception ex) { var a = new CallbackExceptionEventArgs(ex); a.Detail["context"] = "OnConnectionRecoveryError"; _delegate.OnCallbackException(a); } } } return(false); }
private Task StartRecoveryLoop() { return Task.Run(async () => { try { while (true) { await _reader.ReadAsync(_recoveryCancellationToken.Token).ConfigureAwait(false); if (!IsOpened) { await DisposeInnerConnection().ConfigureAwait(false); foreach (var recoverable in _recoverables.Values) { recoverable.Suspend(); } _connection = await CreateConnection(_recoveryCancellationToken.Token).ConfigureAwait(false); foreach (var recoverable in _recoverables.Values) { await recoverable.RecoverAsync(_connection, _recoveryCancellationToken.Token).ConfigureAwait(false); recoverable.Resume(); } _connection.ConnectionClosed += OnConnectionClosed; Log.ConnectionRecovered(_logger); ConnectionRecovered?.Invoke(this, new ConnectionRecoveredEventArgs(_connection.Endpoint)); } else { // If the connection is already opened it means that there may be some suspended recoverables that need to be resumed foreach (var recoverable in _recoverables.Values) { recoverable.Resume(); } } } } catch (OperationCanceledException) { // expected when recovery cancellation token is set. } catch (Exception e) { Log.MainRecoveryLoopException(_logger, e); foreach (var recoverable in _recoverables.Values) { await recoverable.TerminateAsync(e).ConfigureAwait(false); } ConnectionRecoveryError?.Invoke(this, new ConnectionRecoveryErrorEventArgs(e)); } }); }
private void OnConnectionRecoveryError(object sender, ConnectionRecoveryErrorEventArgs e) { ConnectionRecoveryError?.Invoke(sender, e); }
protected void RaiseConnectionRecoveryError(object sender, ConnectionRecoveryErrorEventArgs connectionRecoveryErrorEventArgs) { ConnectionRecoveryError?.Invoke(sender, connectionRecoveryErrorEventArgs); }