/// <summary> /// Initializes a new instance of the <see cref="WrappedAsyncStreamReader{TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse}"/> class. /// </summary> /// <param name="requestId">The request id for the gRPC method call.</param> /// <param name="originalStream">The original gRPC stream reader to wrap.</param> /// <param name="messageConverter">The message converter to use to convert the first message received.</param> /// <param name="metrics">The metrics collector to use for metrics about reverse call stream reads.</param> /// <param name="logger">The logger to use.</param> /// <param name="cancellationToken">A cancellation token to use for cancelling pending and future reads.</param> public WrappedAsyncStreamReader( RequestId requestId, IAsyncStreamReader <TClientMessage> originalStream, IConvertReverseCallMessages <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> messageConverter, IMetricsCollector metrics, ILogger logger, CancellationToken cancellationToken) { _requestId = requestId; _originalStream = originalStream; _messageConverter = messageConverter; _metrics = metrics; _logger = logger; _cancellationToken = cancellationToken; }
/// <inheritdoc/> public IReverseCallDispatcher <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> GetFor <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse>( IAsyncStreamReader <TClientMessage> clientStream, IServerStreamWriter <TServerMessage> serverStream, ServerCallContext context, IConvertReverseCallMessages <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> messageConverter) where TClientMessage : IMessage, new() where TServerMessage : IMessage, new() where TConnectArguments : class where TConnectResponse : class where TRequest : class where TResponse : class => new ReverseCallDispatcher <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse>( _pingedConnectionFactory.CreatePingedReverseCallConnection(_requestIdentifier.GetRequestIdFor(context), clientStream, serverStream, context, messageConverter), messageConverter, _executionContextCreator, _metricsCollector, _loggerFactory.CreateLogger <ReverseCallDispatcher <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> >());
/// <inheritdoc/> public IPingedConnection <TClientMessage, TServerMessage> CreatePingedReverseCallConnection <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse>( RequestId requestId, IAsyncStreamReader <TClientMessage> runtimeStream, IAsyncStreamWriter <TServerMessage> clientStream, ServerCallContext context, IConvertReverseCallMessages <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> messageConverter) where TClientMessage : IMessage, new() where TServerMessage : IMessage, new() where TConnectArguments : class where TConnectResponse : class where TRequest : class where TResponse : class => new PingedConnection <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse>( requestId, runtimeStream, clientStream, context, messageConverter, new TokenSourceDeadline(), _callbackScheduler, _metricsCollector, _loggerFactory);
/// <summary> /// Initializes a new instance of the <see cref="PingedConnection{TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse}"/> class. /// </summary> /// <param name="requestId">The request id for the gRPC method call.</param> /// <param name="runtimeStream">The <see cref="IAsyncStreamReader{TClientMessage}"/> to read messages to the Runtime.</param> /// <param name="clientStream">The <see cref="IServerStreamWriter{TServerMessage}"/> to write messages to the Client.</param> /// <param name="context">The <see cref="ServerCallContext"/> of the method call.</param> /// <param name="messageConverter">The <see cref="MethodConverter"/> to use for decoding the connect arguments and reading the desired ping interval from.</param> /// <param name="keepalive">The keepalive token canceller to use for keeping track of ping timeouts.</param> /// <param name="pingScheduler">The callback scheduler to use for scheduling accurate pings.</param> /// <param name="metrics">The metrics collector to use for metrics about reverse calls.</param> /// <param name="loggerFactory">The logger factory to use to create loggers.</param> public PingedConnection( RequestId requestId, IAsyncStreamReader <TClientMessage> runtimeStream, IAsyncStreamWriter <TServerMessage> clientStream, ServerCallContext context, IConvertReverseCallMessages <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> messageConverter, ICancelTokenIfDeadlineIsMissed keepalive, ICallbackScheduler pingScheduler, IMetricsCollector metrics, ILoggerFactory loggerFactory) { _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(context.CancellationToken, keepalive.Token); _requestId = requestId; _keepalive = keepalive; _pingScheduler = pingScheduler; _wrappedReader = new WrappedAsyncStreamReader <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse>( requestId, runtimeStream, messageConverter, metrics, loggerFactory.CreateLogger <WrappedAsyncStreamReader <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> >(), _cancellationTokenSource.Token); _wrappedWriter = new WrappedAsyncStreamWriter <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse>( requestId, clientStream, messageConverter, metrics, loggerFactory.CreateLogger <WrappedAsyncStreamWriter <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> >(), _cancellationTokenSource.Token); _metrics = metrics; _logger = loggerFactory.CreateLogger <PingedConnection <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> >(); WaitForCallContextInFirstMessageThenStartPinging(); _keepAliveExpiredRegistration = keepalive.Token.Register(NotifyKeepaliveTimedOut); }