示例#1
0
        internal T Send <T>(IOrientDBOperation <T> operation)
        {
            Exception _lastException = null;

            var i = maxAttempts;

            while (i-- > 0)
            {
                try
                {
                    var stream = GetNetworkStream();

                    T result = Process(operation, stream);

                    ReturnStream(stream);

                    return(result);
                }
                catch (IOException ex)
                {
                    if (_lastException == null)
                    {
                        _lastException = ex;
                    }
                    else
                    {
                        _lastException = new Exception("Retry patern exception", ex);
                    }
                }
            }

            throw _lastException;
        }
示例#2
0
        internal T Send <T>(IOrientDBOperation <T> operation)
        {
            Exception lastException = null;

            var i = maxAttempts;

            while (i-- > 0)
            {
                try
                {
                    var stream = GetNetworkStream();

                    T result = Process(operation, stream);

                    ReturnStream(stream);

                    return(result);
                }
                catch (IOException ex)
                {
                    lastException = lastException == null ? ex : new Exception("Retry patern exception", ex);
                }
            }

            throw lastException ?? throw new Exception("Retry patern exception");
        }
示例#3
0
        private async Task <T> ProcessAsync <T>(IOrientDBOperation <T> operation, OrientDBNetworkConnection stream)
        {
            try
            {
                var request = operation.CreateRequest(stream.SessionId, stream.Token);

                var reader = await SendAsync(request, stream.GetStream());

                return(operation.Execute(reader));
            }
            catch
            {
                Destroy(stream);
                throw;
            }
        }
示例#4
0
        internal async Task <T> SendAsync <T>(IOrientDBOperation <T> operation)
        {
            var policy = Policy
                         .Handle <IOException>()
                         .WaitAndRetryAsync(
                maxAttempts,
                retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                );

            return(await policy.ExecuteAsync(async() =>
            {
                var stream = GetNetworkStream();
                var result = await ProcessAsync(operation, stream);
                ReturnStream(stream);
                return result;
            }));
        }
示例#5
0
        private T Process <T>(IOrientDBOperation <T> operation, OrientDBNetworkConnection stream)
        {
            try
            {
                Request request = operation.CreateRequest(stream.SessionId, stream.Token);

                var reader = Send(request, stream.GetStream());

                T result = operation.Execute(reader);

                return(result);
            }
            catch
            {
                Destroy(stream);
                throw;
            }
        }