Task <bool> ITransportDelegator.PingAsync(ITransportRequestState requestState) { int pingTimeout = Settings.PingTimeout.GetValueOrDefault(DefaultPingTimeout); pingTimeout = requestState.RequestConfiguration != null ? requestState.RequestConfiguration.ConnectTimeout.GetValueOrDefault(pingTimeout) : pingTimeout; var requestOverrides = new RequestConfiguration { ConnectTimeout = pingTimeout, RequestTimeout = pingTimeout }; IRequestTimings rq = requestState.InitiateRequest(RequestType.Ping); try { return(Connection.Head(requestState.CreatePathOnCurrentNode(""), requestOverrides) .ContinueWith(t => { if (t.IsFaulted) { rq.Finish(false, null); rq.Dispose(); throw new PingException(requestState.CurrentNode, t.Exception); } rq.Finish(t.Result.Success, t.Result.HttpStatusCode); rq.Dispose(); OrientdbResponse <Stream> response = t.Result; if (!response.HttpStatusCode.HasValue || response.HttpStatusCode.Value == -1) { throw new PingException(requestState.CurrentNode, t.Exception); } if (response.HttpStatusCode == (int)HttpStatusCode.Unauthorized) { throw new OrientdbAuthenticationException(response); } using (response.Response) return response.Success; })); } catch (OrientdbAuthenticationException) { throw; } catch (Exception e) { var tcs = new TaskCompletionSource <bool>(); var pingException = new PingException(requestState.CurrentNode, e); tcs.SetException(pingException); return(tcs.Task); } }
private Task <ElasticsearchResponse <T> > HandleStreamResponse <T>(Task <ElasticsearchResponse <Stream> > t, IRequestTimings rq, TransportRequestState <T> requestState) { var streamResponse = t.Result; // Audit the call into connection straight away rq.Finish(streamResponse != null && streamResponse.Success, streamResponse == null ? -1 : streamResponse.HttpStatusCode); rq.Dispose(); // Figure out the maximum number of retries, this might var maxRetries = this._delegator.GetMaximumRetries(requestState.RequestConfiguration); var retried = requestState.Retried; // If we haven't recieved a successful response and we are not yet done processing the stream attempt a retry if (t.Status != TaskStatus.RanToCompletion || !this.DoneProcessing(streamResponse, requestState, maxRetries, retried)) { return(this.RetryRequestAsync <T>(requestState)); } // If the response never recieved a status code and has a caught exception make sure we throw it if (streamResponse.HttpStatusCode.GetValueOrDefault(-1) <= 0 && streamResponse.OriginalException != null) { throw streamResponse.OriginalException; } // If the user explicitly wants a stream return the undisposed stream if (typeof(Stream).IsAssignableFrom(typeof(T))) { return(this.ReturnResponseAsTask <T>(streamResponse)); } var readResponseTask = (typeof(VoidResponse).IsAssignableFrom(typeof(T))) ? this.ReturnVoidResponse <T>(streamResponse) : this.ReturnTypedResponse(streamResponse, requestState); return(readResponseTask.ContinueWith(gotTypedResponse => { var r = gotTypedResponse.Result; if (this._settings.KeepRawResponse) { r.Response.ResponseRaw = r.Bytes; } this.OptionallyCloseResponseStreamAndSetSuccess(requestState, r.Error, r.Response, t.Result); if (r.Error != null && this._settings.ThrowOnElasticsearchServerExceptions) { throw new ElasticsearchServerException(r.Error); } if (r.Response.SuccessOrKnownError) { this._connectionPool.MarkAlive(requestState.CurrentNode); } return r.Response; })); }
private OrientdbResponse <Stream> DoOrientdbCall <T>(TransportRequestState <T> requestState) { // Do the actual request by calling into IConnection // We wrap it in a IRequestTimings to audit the request OrientdbResponse <Stream> streamResponse; using (IRequestTimings requestAudit = requestState.InitiateRequest(RequestType.OrientdbCall)) { streamResponse = CallInToConnection(requestState); requestAudit.Finish(streamResponse.Success, streamResponse.HttpStatusCode); } return(streamResponse); }
/* PING/SNIFF *** ********************************************/ bool ITransportDelegator.Ping(ITransportRequestState requestState) { int pingTimeout = Settings.PingTimeout.GetValueOrDefault(DefaultPingTimeout); pingTimeout = requestState.RequestConfiguration != null ? requestState.RequestConfiguration.ConnectTimeout.GetValueOrDefault(pingTimeout) : pingTimeout; var requestOverrides = new RequestConfiguration { ConnectTimeout = pingTimeout, RequestTimeout = pingTimeout }; try { OrientdbResponse <Stream> response; using (IRequestTimings rq = requestState.InitiateRequest(RequestType.Ping)) { response = Connection.HeadSync(requestState.CreatePathOnCurrentNode(""), requestOverrides); rq.Finish(response.Success, response.HttpStatusCode); } if (!response.HttpStatusCode.HasValue || response.HttpStatusCode.Value == -1) { throw new Exception("ping returned no status code", response.OriginalException); } if (response.HttpStatusCode == (int)HttpStatusCode.Unauthorized) { throw new OrientdbAuthenticationException(response); } if (response.Response == null) { return(response.Success); } using (response.Response) return(response.Success); } catch (OrientdbAuthenticationException) { throw; } catch (Exception e) { throw new PingException(requestState.CurrentNode, e); } }