Example #1
0
        private async Task <List <DeliverResponse> > DeliverAsync(ADStreamingCall <Envelope, DeliverResponse> call, Envelope envelope, CancellationToken token)
        {
            List <DeliverResponse> ret = new List <DeliverResponse>();
            var rtask = Task.Run(async() =>
            {
                while (await call.Call.ResponseStream.MoveNext(token).ConfigureAwait(false))
                {
                    token.ThrowIfCancellationRequested();
                    DeliverResponse resp = call.Call.ResponseStream.Current;
                    logger.Debug($"{this} resp status value: {resp.Status}, type case: {resp.TypeCase}");
                    if (resp.TypeCase == DeliverResponse.TypeOneofCase.Status)
                    {
                        ret.Insert(0, resp);
//TODO: mpiva: Review this, original JAVA code will throw exception on no success, channel init code, check for the status (Not Found) for retrying.
//TODO: mpiva: Report this as an error to the original JAVA SDK repo.
//                      if (resp.Status == Status.Success)
                        return;

                        /*if (shutdown)
                         *  throw new OperationCanceledException($"Channel {channelName}, sendDeliver were canceled");
                         * throw new TransactionException($"Channel {channelName} orderer {name} status finished with failure code {resp.Status} during order registration");
                         */
                    }

                    ret.Add(resp);
                }
            }, token);
            await call.Call.RequestStream.WriteAsync(envelope).ConfigureAwait(false);

            token.ThrowIfCancellationRequested();
            await rtask.TimeoutAsync(TimeSpan.FromMilliseconds(ordererWaitTimeMilliSecs), token).ConfigureAwait(false);

            logger.Trace($"{this} Deliver Complete.");
            return(ret);
        }
Example #2
0
        private async Task <BroadcastResponse> BroadcastAsync(ADStreamingCall <Envelope, BroadcastResponse> call, Envelope envelope, CancellationToken token)
        {
            BroadcastResponse resp = null;
            var rtask = Task.Run(async() =>
            {
                if (await call.Call.ResponseStream.MoveNext(token).ConfigureAwait(false))
                {
                    token.ThrowIfCancellationRequested();
                    resp = call.Call.ResponseStream.Current;
                    logger.Debug($"{this} resp status value: {resp.Status}, resp: {resp.Info}");
//TODO: mpiva: Review this, original JAVA code will throw exception on no success, channel init code, check for the status (Not Found) for retrying.
//TODO: mpiva: Report this as an error to the original JAVA SDK repo.

                    /*
                     * if (shutdown)
                     *  throw new OperationCanceledException($"Channel {channelName}, sendTransaction were canceled");
                     * throw new TransactionException($"Channel {channelName} orderer {name} status returned failure code {resp.Status} ({resp.Info}) during order registration");*/
                }
            }, token);
            await call.Call.RequestStream.WriteAsync(envelope).ConfigureAwait(false);

            token.ThrowIfCancellationRequested();
            await rtask.TimeoutAsync(TimeSpan.FromMilliseconds(ordererWaitTimeMilliSecs), token).ConfigureAwait(false);

            logger.Trace($"{this} Broadcast Complete.");
            return(resp);
        }