Create() 공개 정적인 메소드

public static Create ( ) : CompletionQueueSafeHandle
리턴 CompletionQueueSafeHandle
예제 #1
0
파일: AsyncCall.cs 프로젝트: varung/grpc
        // TODO: this method is not Async, so it shouldn't be in AsyncCall class, but
        // it is reusing fair amount of code in this class, so we are leaving it here.
        // TODO: for other calls, you need to call Initialize, this methods calls initialize
        // on its own, so there's a usage inconsistency.
        /// <summary>
        /// Blocking unary request - unary response call.
        /// </summary>
        public TResponse UnaryCall(Channel channel, string methodName, TRequest msg, Metadata headers)
        {
            using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
            {
                byte[] payload = UnsafeSerialize(msg);

                unaryResponseTcs = new TaskCompletionSource <TResponse>();

                lock (myLock)
                {
                    Initialize(channel, cq, methodName);
                    started            = true;
                    halfcloseRequested = true;
                    readingDone        = true;
                }

                using (var metadataArray = MetadataArraySafeHandle.Create(headers))
                {
                    call.BlockingUnary(cq, payload, unaryResponseHandler, metadataArray);
                }

                try
                {
                    // Once the blocking call returns, the result should be available synchronously.
                    return(unaryResponseTcs.Task.Result);
                }
                catch (AggregateException ae)
                {
                    throw ExceptionHelper.UnwrapRpcException(ae);
                }
            }
        }
예제 #2
0
        public TRead UnaryCall(Channel channel, String methodName, TWrite msg)
        {
            using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
            {
                // TODO: handle serialization error...
                byte[] payload = serializer(msg);

                unaryResponseTcs = new TaskCompletionSource <TRead>();

                lock (myLock)
                {
                    Initialize(channel, cq, methodName);
                    started            = true;
                    halfcloseRequested = true;
                    readingDone        = true;
                }
                call.BlockingUnary(cq, payload, unaryResponseHandler);

                try
                {
                    // Once the blocking call returns, the result should be available synchronously.
                    return(unaryResponseTcs.Task.Result);
                }
                catch (AggregateException ae)
                {
                    throw ExceptionHelper.UnwrapRpcException(ae);
                }
            }
        }
예제 #3
0
        private static ReadOnlyCollection <CompletionQueueSafeHandle> CreateCompletionQueueList(GrpcEnvironment environment, int completionQueueCount)
        {
            var list = new List <CompletionQueueSafeHandle>();

            for (int i = 0; i < completionQueueCount; i++)
            {
                var completionRegistry = new CompletionRegistry(environment);
                list.Add(CompletionQueueSafeHandle.Create(completionRegistry));
            }
            return(list.AsReadOnly());
        }
예제 #4
0
파일: AsyncCall.cs 프로젝트: zz198808/grpc
        // TODO: this method is not Async, so it shouldn't be in AsyncCall class, but
        // it is reusing fair amount of code in this class, so we are leaving it here.
        /// <summary>
        /// Blocking unary request - unary response call.
        /// </summary>
        public TResponse UnaryCall(TRequest msg)
        {
            var profiler = Profilers.ForCurrentThread();

            using (profiler.NewScope("AsyncCall.UnaryCall"))
                using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
                {
                    byte[] payload = UnsafeSerialize(msg);

                    unaryResponseTcs = new TaskCompletionSource <TResponse>();

                    lock (myLock)
                    {
                        GrpcPreconditions.CheckState(!started);
                        started = true;
                        Initialize(cq);

                        halfcloseRequested = true;
                        readingDone        = true;
                    }

                    using (var metadataArray = MetadataArraySafeHandle.Create(details.Options.Headers))
                        using (var ctx = BatchContextSafeHandle.Create())
                        {
                            call.StartUnary(ctx, payload, metadataArray, GetWriteFlagsForCall());

                            var ev = cq.Pluck(ctx.Handle);

                            bool success = (ev.success != 0);
                            try
                            {
                                using (profiler.NewScope("AsyncCall.UnaryCall.HandleBatch"))
                                {
                                    HandleUnaryResponse(success, ctx.GetReceivedStatusOnClient(), ctx.GetReceivedMessage(), ctx.GetReceivedInitialMetadata());
                                }
                            }
                            catch (Exception e)
                            {
                                Logger.Error(e, "Exception occured while invoking completion delegate.");
                            }
                        }

                    // Once the blocking call returns, the result should be available synchronously.
                    // Note that GetAwaiter().GetResult() doesn't wrap exceptions in AggregateException.
                    return(unaryResponseTcs.Task.GetAwaiter().GetResult());
                }
        }
예제 #5
0
        public void Start()
        {
            lock (myLock)
            {
                if (cq != null)
                {
                    throw new InvalidOperationException("Already started.");
                }

                cq = CompletionQueueSafeHandle.Create();

                for (int i = 0; i < poolSize; i++)
                {
                    threads.Add(CreateAndStartThread(i));
                }
            }
        }
예제 #6
0
파일: AsyncCall.cs 프로젝트: hmings888/grpc
        // TODO: this method is not Async, so it shouldn't be in AsyncCall class, but
        // it is reusing fair amount of code in this class, so we are leaving it here.
        // TODO: for other calls, you need to call Initialize, this methods calls initialize
        // on its own, so there's a usage inconsistency.
        /// <summary>
        /// Blocking unary request - unary response call.
        /// </summary>
        public TResponse UnaryCall(Channel channel, string methodName, TRequest msg, Metadata headers)
        {
            using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
            {
                byte[] payload = UnsafeSerialize(msg);

                unaryResponseTcs = new TaskCompletionSource <TResponse>();

                lock (myLock)
                {
                    Initialize(channel, cq, methodName);
                    started            = true;
                    halfcloseRequested = true;
                    readingDone        = true;
                }

                using (var metadataArray = MetadataArraySafeHandle.Create(headers))
                {
                    using (var ctx = BatchContextSafeHandle.Create())
                    {
                        call.StartUnary(payload, ctx, metadataArray);
                        var ev = cq.Pluck(ctx.Handle);

                        bool success = (ev.success != 0);
                        try
                        {
                            HandleUnaryResponse(success, ctx);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Exception occured while invoking completion delegate: " + e);
                        }
                    }
                }

                try
                {
                    // Once the blocking call returns, the result should be available synchronously.
                    return(unaryResponseTcs.Task.Result);
                }
                catch (AggregateException ae)
                {
                    throw ExceptionHelper.UnwrapRpcException(ae);
                }
            }
        }