Example #1
0
 /// <summary>
 /// This helper ensures we invalidate the _currentCall state if we want to throw canceled.
 /// </summary>
 private void ThrowIfCancellationRequested(CancellationToken cancellationToken)
 {
     if (cancellationToken.IsCancellationRequested)
     {
         _currentCall?.Dispose();
         _currentCall = null;
         cancellationToken.ThrowIfCancellationRequested();
     }
 }
        /// <exclude />
        public static async Task <IAsyncEnumerable <T> > GetServerStreamingCallResultAsync <T>(
            AsyncServerStreamingCall <Message <T> > call,
            CallContext?context,
            CancellationToken token)
        {
            try
            {
                if (context != null && !token.IsCancellationRequested)
                {
                    var headers = await call.ResponseHeadersAsync.ConfigureAwait(false);

                    context.ServerResponse = new ServerResponse(
                        headers,
                        call.GetStatus,
                        call.GetTrailers);
                }
            }
            catch
            {
                call.Dispose();
                throw;
            }

            return(ReadServerStreamingCallResultAsync(call, context, token));
        }
        public Task DisconnectAsync()
        {
            _cts.Cancel();
            _call?.Dispose();

            return(Task.CompletedTask);
        }
 public void Dispose()
 {
     _cts?.Cancel();
     _cts?.Dispose();
     _stream?.Dispose();
     channel?.Dispose();
 }
 public void Dispose()
 {
     _cts?.Cancel();
     _cts?.Dispose();
     _stream?.Dispose();
     channel?.ShutdownAsync();
 }
Example #6
0
 public void Shutdown()
 {
     Logger.Info("Shutting down...");
     _client.Quit(new QuitRequest());
     _commandStream?.Dispose();
     _channel.ShutdownAsync().Wait();
     Logger.Info("All down.");
 }
 public async Task DisconnectAsync()
 {
     _cts.Cancel();
     _call?.Dispose();
     if (_channel != null)
     {
         await _channelFactory.DisposeAsync(_channel);
     }
 }
Example #8
0
 public async Task DisconnectAsync()
 {
     _cts.Cancel();
     _call?.Dispose();
     if (_channel != null)
     {
         await _channel.ShutdownAsync();
     }
 }
Example #9
0
 /// <summary>
 /// </summary>
 public void Close()
 {
     if (IsClosed)
     {
         return;
     }
     IsClosed = true;
     _currentCall?.Dispose();
     StreamClosed?.Invoke(this, new StreamClosedEventArgs());
 }
        public void Dispose()
        {
            _holdingLineRequest?.Dispose();
            _channel?.ShutdownAsync().Wait(TimeSpan.FromSeconds(5));
            _channel?.Dispose();

            StartStreamCallback      = default;
            StopStreamCallback       = default;
            CloseApplicationCallback = default;
        }
 /// <summary>
 /// 使用しているリソースを解放します。
 /// </summary>
 /// <param name="disposing">dispose メソッドから呼び出されたかどうか</param>
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (m_DisposableCall)
         {
             m_Call.Dispose();
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Example #12
0
 public void Shutdown()
 {
     if (_invoiceStream != null)
     {
         _invoiceStream.Dispose();
     }
     if (_graphStream != null)
     {
         _graphStream.Dispose();
     }
     if (_transactionStream != null)
     {
         _transactionStream.Dispose();
     }
     rpcChannel.ShutdownAsync().Wait();
 }
Example #13
0
 Action <bool> onNextFn(AsyncServerStreamingCall <Example.HelloReply> call)
 {
     return(ok =>
     {
         if (ok)
         {
             replyCount++;
             Example.HelloReply helloReply = call.ResponseStream.Current;
             Debug.Log("Got " + replyCount.ToString() + " greeting, I think: " + helloReply.Message);
             call.ResponseStream.MoveNext().StartAsCoroutine <bool>(this.onNextFn(call));
         }
         else
         {
             Debug.Log("End of stream or failure. Status: " + call.GetStatus() + ". Retrying!");
             call.Dispose();
         }
     });
 }
Example #14
0
 public async Task Subscribe()
 {
     try
     {
         call = Client.SubscribeForMessages(new SubscribtionRequest()
         {
         });
         while (await call.ResponseStream.MoveNext())
         {
             Message mess = call.ResponseStream.Current;
             commonWriter.PutData(mess);
             //Console.WriteLine(string.Format("New Message! " +
             //    "ChatId: {0}; MessageId: {1}; Text: {2};", mess.ChatId, mess.Id, mess.Text));
         }
     }
     catch (Grpc.Core.RpcException ex)
     {
         call.Dispose();
     }
 }
Example #15
0
        public void Dispose()
        {
            subscriptionThread?.Abort();
            subscriptionThread = null;

            if (subscriptionListener != null)
            {
                subscriptionListener.ServerEventReceived -= _eventHandler.Invoke;
                subscriptionListener.Dispose();
                subscriptionListener = null;
            }

            subscription?.Dispose();
            subscription = null;

            workingTaskCancellationTokenSource?.Cancel();
            workingTaskCancellationTokenSource?.Dispose();
            workingTaskCancellationTokenSource = null;

            isListening = false;
        }
        private async Task TryRecoverOnFailureAsync(CancellationToken cancellationToken, Exception exception)
        {
            _currentCall?.Dispose();
            _currentCall = null;

            //reconnect on failure which will call reliableconnect and respect resumetoken and resumeskip
            cancellationToken.ThrowIfCancellationRequested();

            Logger.Warn(
                () =>
                $"An error occurred attemping to iterate through the sql query.  Attempting to recover. Exception:{exception}");

            //when we reconnect, we purposely do not do a *reliable*movenext.  If we fail to fast forward on the reconnect
            //we bail out completely and surface the error.
            _isReading = await ReliableConnectAsync(cancellationToken).ConfigureAwait(false);

            if (_isReading)
            {
                // we try one more time to advance. Note that we should have done an exponential backoff retry
                // on the initial connect -- but MoveNext is not idempotent, so all we can do if it fails is start
                // from scratch.  But in case something is going horribly awry, we don't want to spin indefinitely,
                // so we bail if the recovery isn't successful in moving to the next item.
                try
                {
                    _isReading = await _currentCall.ResponseStream.MoveNext(cancellationToken)
                                 .WithSessionChecking(() => _session).ConfigureAwait(false);

                    _resumeSkipCount++;
                }
                catch (Exception e)
                {
                    Logger.Warn(() => $"An error occurred attemping to recover. Exception:{e}");
                    //At this point, we give up, rethrowing and setting state such that it will
                    //need to reconnect if the user calls MoveNext again.
                    _currentCall?.Dispose();
                    _currentCall = null;
                    throw;
                }
            }
        }
Example #17
0
    // StartServerStream starts a background task listening to server responses
    // https://github.com/grpc/grpc/issues/21734#issuecomment-578519701
    private async Task <AsyncServerStreamingCall <GameData> > StartServerStream()
    {
        try
        {
            while (await _stream.ResponseStream.MoveNext())
            {
                _tokenSource.Token.ThrowIfCancellationRequested();

                GameData gd = _stream.ResponseStream.Current;
                game.Set(gd);
                game.PlayerRealPosition = gd.Player.Position;

                // Debug.Log($"> {gd}");

                AckIfNeeded(gd.Info.AckToken);
            }
        }
        catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled)
        {
            _mGameFailedEvent.Invoke($"Stream cancelled: {ex}");
        }
        catch (OperationCanceledException ex)
        {
            _mGameFailedEvent.Invoke($"server streaming thread cancelled: {ex}");
            _stream.Dispose();
        }
        catch (RpcException ex)
        {
            _mGameFailedEvent.Invoke(ex.ToString());
        }
        catch (Exception ex)
        {
            _mGameFailedEvent.Invoke($"Server reading thread failed: {ex}");
            Application.Quit();
        }

        Debug.Log("Exiting server info thread...");
        return(null);
    }
Example #18
0
        /// <summary>
        /// 指定されたメソッド呼び出しを登録します。
        /// </summary>
        /// <typeparam name="TRequest">リクエストの型</typeparam>
        /// <typeparam name="TResponse">レスポンスの型</typeparam>
        /// <param name="call">呼び出しオブジェクト</param>
        /// <param name="method">メソッド</param>
        /// <param name="host">ホスト</param>
        /// <param name="options">オプション</param>
        /// <param name="performanceListener">パフォーマンスリスナー</param>
        /// <returns>呼び出しオブジェクト</returns>
        internal static AsyncServerStreamingCall <TResponse> Regist <TRequest, TResponse>(AsyncServerStreamingCall <TResponse> call, Method <TRequest, TResponse> method, string host, CallOptions options, GrpcClientPerformanceListener performanceListener)
        {
            GrpcCallInvokerContext.Releaser releaser = new GrpcCallInvokerContext.Releaser(delegate()
            {
                call.Dispose();
            });

            GrpcCallState state = new GrpcCallState(method, host, options);

            AsyncServerStreamingCall <TResponse> wrap = new AsyncServerStreamingCall <TResponse>(
                new ResponseStreamReader <TResponse>(call.ResponseStream, method, host, options, state.OnEndResponse, performanceListener)
                , call.ResponseHeadersAsync
                , call.GetStatus
                , call.GetTrailers
                , releaser.Dispose
                );

            releaser.Target = wrap;

            GrpcCallInvokerContext.AddState(wrap, state);

            return(wrap);
        }
 public void Dispose()
 {
     _call.Dispose();
 }
Example #20
0
 public void Dispose()
 {
     m_Call.Dispose();
 }
Example #21
0
 public void Dispose()
 {
     _cancelSource.Cancel();
     _streamingCall?.Dispose();
 }
Example #22
0
 protected new void OnDestroy()
 {
     this.RunCatching(_ => looper.Dispose());
     this.RunCatching(_ => call.Dispose());
     base.OnDestroy();
 }