Ejemplo n.º 1
0
        public GrpcCall(Method <TRequest, TResponse> method, CallOptions options, HttpClientCallInvoker callInvoker)
        {
            // Validate deadline before creating any objects that require cleanup
            ValidateDeadline(options.Deadline);

            _callCts    = new CancellationTokenSource();
            _callTcs    = new TaskCompletionSource <StatusCode>(TaskContinuationOptions.RunContinuationsAsynchronously);
            Method      = method;
            _uri        = new Uri(method.FullName, UriKind.Relative);
            _logScope   = new GrpcCallScope(method.Type, _uri);
            Options     = options;
            CallInvoker = callInvoker;
            Logger      = callInvoker.LoggerFactory.CreateLogger <GrpcCall <TRequest, TResponse> >();

            if (options.CancellationToken.CanBeCanceled)
            {
                // The cancellation token will cancel the call CTS
                _ctsRegistration = options.CancellationToken.Register(() =>
                {
                    using (StartScope())
                    {
                        CancelCall();
                    }
                });
            }

            if (options.Deadline != null && options.Deadline != DateTime.MaxValue)
            {
                var timeout = options.Deadline.GetValueOrDefault() - CallInvoker.Clock.UtcNow;
                _timeout = (timeout > TimeSpan.Zero) ? timeout : TimeSpan.Zero;
            }
        }
Ejemplo n.º 2
0
        public GrpcCall(Method <TRequest, TResponse> method, CallOptions options, ISystemClock clock, ILoggerFactory loggerFactory)
        {
            // Validate deadline before creating any objects that require cleanup
            ValidateDeadline(options.Deadline);

            _callCts  = new CancellationTokenSource();
            Method    = method;
            _uri      = new Uri(method.FullName, UriKind.Relative);
            _logScope = new GrpcCallScope(method.Type, _uri);
            Options   = options;
            _clock    = clock;
            Logger    = loggerFactory.CreateLogger <GrpcCall <TRequest, TResponse> >();

            if (options.CancellationToken.CanBeCanceled)
            {
                // The cancellation token will cancel the call CTS
                _ctsRegistration = options.CancellationToken.Register(() =>
                {
                    using (StartScope())
                    {
                        CancelCall();
                    }
                });
            }

            if (options.Deadline != null && options.Deadline != DateTime.MaxValue)
            {
                var timeout = options.Deadline.GetValueOrDefault() - _clock.UtcNow;
                _timeout = (timeout > TimeSpan.Zero) ? timeout : TimeSpan.Zero;
            }
        }
Ejemplo n.º 3
0
        public GrpcCall(Method <TRequest, TResponse> method, CallOptions options, GrpcChannel channel)
        {
            // Validate deadline before creating any objects that require cleanup
            ValidateDeadline(options.Deadline);

            _callCts  = new CancellationTokenSource();
            _callTcs  = new TaskCompletionSource <Status>(TaskContinuationOptions.RunContinuationsAsynchronously);
            Method    = method;
            _uri      = new Uri(method.FullName, UriKind.Relative);
            _logScope = new GrpcCallScope(method.Type, _uri);
            Options   = options;
            Channel   = channel;
            Logger    = channel.LoggerFactory.CreateLogger <GrpcCall <TRequest, TResponse> >();

            if (options.Deadline != null && options.Deadline != DateTime.MaxValue)
            {
                var timeout = options.Deadline.GetValueOrDefault() - Channel.Clock.UtcNow;
                _timeout = (timeout > TimeSpan.Zero) ? timeout : TimeSpan.Zero;
            }
        }
Ejemplo n.º 4
0
 public GrpcMethodInfo(GrpcCallScope logScope, Uri callUri, MethodConfig?methodConfig)
 {
     LogScope     = logScope;
     CallUri      = callUri;
     MethodConfig = CreateMethodConfig(methodConfig);
 }
 public GrpcMethodInfo(GrpcCallScope logScope, Uri callUri)
 {
     LogScope = logScope;
     CallUri  = callUri;
 }