private void ConnectionOnOnFailure(object sender, FailureEventArgs failureEventArgs) { var connection = sender as IConnection; if (null != connection) { connection.OnFailure -= ConnectionOnOnFailure; if (_connection?.connection == connection) { _connection = null; return; } else { // find the connection in connections and remove it. if (appendConnections.Length == 0) { return; } lock (this) { var connections = appendConnections; var leftConnections = connections.Where(c => c.connection != connection).ToArray(); if (leftConnections.Length != connections.Length) { // means we found it in connections. _cluster.DisposeConnection(connection); appendConnections = leftConnections; } } } } }
private void ConnectionOnOnFailure(object sender, FailureEventArgs failureEventArgs) { lock (_lock) { _connection = null; } }
private void OnFailure(object sender, FailureEventArgs e) { IConnection connection = sender as IConnection; if (null != connection && _ip2Connection.ContainsKey(connection.Endpoint)) { IPAddress endpoint = connection.Endpoint; _logger.Error("connection {0} failed with error {1}", endpoint, e.Exception); IConnection[] connections; _ip2Connection.TryRemove(endpoint, out connections); bool isSenderDisposed = false; foreach (var con in connections) { if (con == sender) { isSenderDisposed = true; } con.SafeDispose(); } if (isSenderDisposed == false) { sender.SafeDispose(); } MarkEndpointForRecovery(endpoint); } }
protected virtual void OnFailed(FailureEventArgs args) { var failed = this.Failed; if (failed != null) { failed(this, args); } }
private void ConnectionOnOnFailure(object sender, FailureEventArgs failureEventArgs) { IConnection connection = _connection; if (null != connection) { connection.OnFailure -= ConnectionOnOnFailure; } _connection = null; }
private void Close(Exception ex) { // already in close state ? lock (_lock) { bool wasClosed = _isClosed; _isClosed = true; Monitor.PulseAll(_lock); if (wasClosed) { return; } // abort all pending queries OperationCanceledException canceledException = new OperationCanceledException(); for (int i = 0; i < _queryInfos.Length; ++i) { var queryInfo = _queryInfos[i]; if (null != queryInfo) { queryInfo.NotifyError(canceledException); _instrumentation.ClientTrace(queryInfo.Token, EventType.Cancellation); _queryInfos[i] = null; } } foreach (var queryInfo in _pendingQueries) { queryInfo.NotifyError(canceledException); _instrumentation.ClientTrace(queryInfo.Token, EventType.Cancellation); } _pendingQueries.Clear(); } // we have now the guarantee this instance is destroyed once _tcpClient.SafeDispose(); if (null != ex && null != OnFailure) { _logger.Fatal("Failed with error : {0}", ex); FailureEventArgs failureEventArgs = new FailureEventArgs(ex); OnFailure(this, failureEventArgs); } // release event to release observer OnFailure = null; }
private void OnFailure(object sender, FailureEventArgs e) { IConnection connection = sender as IConnection; if (null != connection && _ip2Connection.ContainsKey(connection.Endpoint)) { IPAddress endpoint = connection.Endpoint; _logger.Error("connection {0} failed with error {1}", endpoint, e.Exception); _ip2Connection.TryRemove(endpoint, out connection); sender.SafeDispose(); MarkEndpointForRecovery(endpoint); } }
private void OnFailure(object sender, FailureEventArgs e) { lock (_globalLock) { IConnection connection = sender as IConnection; if (null != connection && _ip2Connection.ContainsKey(connection.Endpoint)) { IPAddress endpoint = connection.Endpoint; _logger.Error("connection {0} failed with error {1}", endpoint, e.Exception); _ip2Connection.Remove(endpoint); MarkEndpointForRecovery(endpoint); } } }
private async void OnPublishFailed(RTMPPublishSession sender, FailureEventArgs args) { return; }
private static void WriteVerificationFailureTree(object sender, FailureEventArgs e) { e.Logger.WriteEntry(SinkEntryType.Message, "Full verification failure tree:" + Environment.NewLine + Environment.NewLine + ResultMessageTreeController.Instance.FormatTreeAsText()); }
private void GeneralFailure(Exception ex) { lock (_globalLock) { if (_failed) { return; } _logger.Error("Connection to {0} is broken", Endpoint); _failed = true; // currently running request/response will be abruptly terminated Dispose(); // release all pending client waiting for a response foreach (RequestState requestState in _requestStates) { lock (requestState.Lock) { Monitor.Pulse(requestState.Lock); } } Monitor.Pulse(_globalLock); if (null != OnFailure) { FailureEventArgs failureEventArgs = new FailureEventArgs(ex); OnFailure(this, failureEventArgs); } } }
private void HandleFrameTerminaison(Exception ex, IFrameReader frameReader, byte streamId) { if (null != ex) { _logger.Debug("HandleFrameTerminaison notified with exception {0}", ex); } bool isFatal = ex is IOException || ex is SocketException || ex is OperationCanceledException || null == frameReader; if (! isFatal) { InstrumentationToken token = _queryInfos[streamId].InstrumentationToken; // release streamId now lock (_globalLock) { _queryInfos[streamId] = new QueryInfo(); // release stream id (since result streaming has started) _availableStreamIds.Push(streamId); Monitor.Pulse(_globalLock); } _instrumentation.ClientTrace(token, EventType.EndRead); frameReader.SafeDispose(); if (_streaming) { Task.Factory.StartNew(ReadNextFrameHeader, _cancellation.Token); } if (0 != (token.ExecutionFlags & ExecutionFlags.ServerTracing) && frameReader.TraceId.HasValue) { TracingSession tracingSession = this.GetTracingSession(frameReader.TraceId.Value); _instrumentation.ServerTrace(token, tracingSession); } return; } lock (_globalLock) { _logger.Error("Connection to {0} is broken", Endpoint); if (null != OnFailure) { FailureEventArgs failureEventArgs = new FailureEventArgs(ex); OnFailure(this, failureEventArgs); } } }
private void GeneralFailure(Exception ex) { lock (_globalLock) { _logger.Error("Connection to {0} is broken", Endpoint); _cancellation.Cancel(); // wake up eventually client waiting for a stream id Monitor.Pulse(_globalLock); if (null != OnFailure) { FailureEventArgs failureEventArgs = new FailureEventArgs(ex); OnFailure(this, failureEventArgs); } // currently running request/response will be abruptly terminated Dispose(); } }
private void HandleFrameTerminaison(Exception ex, IFrameReader frameReader, byte streamId) { if (null != ex) { _logger.Debug("HandleFrameTerminaison notified with exception {0}", ex); } bool isFatal = ex is IOException || ex is SocketException || ex is OperationCanceledException; if (! isFatal) { frameReader.SafeDispose(); InstrumentationToken token = _queryInfos[streamId].InstrumentationToken; _instrumentation.ClientTrace(token, EventType.EndRead); _queryInfos[streamId] = new QueryInfo(); // release streamId now lock (_globalLock) { if (_cancellation.IsCancellationRequested) { return; } // release stream id (since result streaming has started) _availableStreamIds.Push(streamId); Monitor.Pulse(_globalLock); if (_streaming && null != frameReader) { Task.Factory.StartNew(ReadNextFrameHeader, _cancellation.Token); } } return; } lock (_globalLock) { _logger.Error("Connection to {0} is broken", Endpoint); if (null != OnFailure) { FailureEventArgs failureEventArgs = new FailureEventArgs(ex); OnFailure(this, failureEventArgs); } } }
private void Failure(Response response, Request request, Exception exception) { var args = new FailureEventArgs(response, request, exception); OnFailureEvent(args); }
/// <summary> /// Called when an error occur /// </summary> /// <param name="e"></param> protected void OnFailureEvent(FailureEventArgs e) { FailureHandler?.Invoke(this, e); }
private void HandleFailure(Exception ex) { _logger.Debug("HandleFailure notified with exception {0}", ex); bool isFatal = ex is IOException || ex is SocketException; if (! isFatal) { _logger.Debug("Exception is not fatal"); return; } lock (_globalLock) { _logger.Error("Connection to {0} is broken", Endpoint); _cancellation.Cancel(); // wake up eventually client waiting for a stream id Monitor.Pulse(_globalLock); if (null != OnFailure) { FailureEventArgs failureEventArgs = new FailureEventArgs(ex); OnFailure(this, failureEventArgs); } // currently running request/response will be abruptly terminated Dispose(); } }