Beispiel #1
0
        private static void Deliver(Request request, Response response, Action action = null)
        {
            if (request.IsCanceled)
            {
                request.Finish("canceled-at-delivery");
                return;
            }

            if (response.IsSuccess)
            {
                request.SetResponse(response);
            }
            else
            {
                request.SetError(response.Error);
            }

            if (response.IsIntermediate)
            {
                request.AddMarker("intermediate-response");
            }
            else
            {
                request.Finish("done");
            }

            if (action != null)
            {
                action();
            }
        }
Beispiel #2
0
        private static void Deliver(Request request, Response response, Action action = null)
        {
            if (request.IsCanceled)
            {
                request.Finish("canceled-at-delivery");
                return;
            }

            if (response.IsSuccess)
            {
                request.SetResponse(response);
            }
            else
            {
                request.SetError(response.Error);
            }

            if (response.IsIntermediate)
            {
                request.AddMarker("intermediate-response");
            }
            else
            {
                request.Finish("done");
            }

            if (action != null)
            {
                action();
            }
        }
Beispiel #3
0
        private static void AttemptRetry(Request request, RequestException exception)
        {
            var retry_policy = request.RetryPolicy;
            var timeout_ms   = retry_policy.CurrentTimeoutMs;

            try
            {
                retry_policy.Retry(exception);
                request.AddMarker(String.Format("retry [timeout={0}]", timeout_ms));
            }
            catch (RequestException)
            {
                request.AddMarker(String.Format("timeout-giveup [timeout={0}]", timeout_ms));
                throw;
            }
        }
Beispiel #4
0
        public void PostError(Request request, Error error)
        {
            request.AddMarker("post-error");
            var response = new Response {
                Error = error
            };

            _invoke(() => Deliver(request, response));
        }
Beispiel #5
0
        public void PostException(Request request, RequestException exception)
        {
            request.AddMarker("post-exception");
            var response = new Response {
                Exception = exception
            };

            Deliver(request, response);
        }
Beispiel #6
0
        public Request Add(Request request)
        {
            lock (_requests)
            {
                _requests.Add(request);
            }

            request.RequestQueue = this;
            request.Sequence     = Interlocked.Increment(ref _sequence);
            request.AddMarker("add-to-queue");

            if (!request.ShouldCache)
            {
                _network_queue.Add(request);
                return(request);
            }

            lock (_blocked_requests)
            {
                List <Request> list;
                if (_blocked_requests.TryGetValue(request.CacheKey, out list))
                {
                    list = list ?? new List <Request>();
                    list.Add(request);

                    _blocked_requests[request.CacheKey] = list;
                }
                else
                {
                    _blocked_requests[request.CacheKey] = null;
                    _cache_queue.Add(request);
                }
            }

            return(request);
        }
Beispiel #7
0
        public Request Add(Request request)
        {
            lock (_requests)
            {
                _requests.Add(request);
            }

            request.RequestQueue = this;
            request.Sequence = Interlocked.Increment(ref _sequence);
            request.AddMarker("add-to-queue");

            if (!request.ShouldCache)
            {
                _network_queue.Add(request);
                return request;
            }

            lock (_blocked_requests)
            {
                List<Request> list;
                if (_blocked_requests.TryGetValue(request.CacheKey, out list))
                {
                    list = list ?? new List<Request>();
                    list.Add(request);

                    _blocked_requests[request.CacheKey] = list;
                }
                else
                {
                    _blocked_requests[request.CacheKey] = null;
                    _cache_queue.Add(request);
                }
            }

            return request;
        }
Beispiel #8
0
 public void PostResponse(Request request, Response response, Action action = null)
 {
     request.AddMarker("post-response");
     _invoke(() => Deliver(request, response, action));
 }
Beispiel #9
0
 public void PostError(Request request, Error error)
 {
     request.AddMarker("post-error");
     var response = new Response { Error = error };
     _invoke(() => Deliver(request, response));
 }
Beispiel #10
0
 public void PostResponse(Request request, Response response, Action action = null)
 {
     request.AddMarker("post-response");
     _invoke(() => Deliver(request, response, action));
 }
Beispiel #11
0
        private static void AttemptRetry(Request request, Error error)
        {
            var retry_policy = request.RetryPolicy;
            var timeout_ms = retry_policy.CurrentTimeoutMs;

            try
            {
                retry_policy.Retry(error);
                request.AddMarker(String.Format("retry [timeout={0}]", timeout_ms));
            }
            catch (Error)
            {
                request.AddMarker(String.Format("timeout-giveup [timeout={0}]", timeout_ms));
                throw;
            }
        }