예제 #1
0
파일: Requestor.cs 프로젝트: cunchy0/avro-1
        private void Request <T>(RpcRequest request, ICallback <T> callback)
        {
            Transceiver t = transceiver;

            if (!t.IsConnected)
            {
                Monitor.Enter(handshakeLock);
                handshakeThread = Thread.CurrentThread;

                try
                {
                    if (!t.IsConnected)
                    {
                        var callFuture             = new CallFuture <T>(callback);
                        IList <MemoryStream> bytes = request.GetBytes(Local, this);
                        var transceiverCallback    = new TransceiverCallback <T>(this, request, callFuture, Local);

                        t.Transceive(bytes, transceiverCallback);

                        // Block until handshake complete
                        callFuture.Wait();
                        Message message = GetMessage(request);
                        if (message.Oneway.GetValueOrDefault())
                        {
                            Exception error = callFuture.Error;
                            if (error != null)
                            {
                                throw error;
                            }
                        }
                        return;
                    }
                }
                finally
                {
                    if (Thread.CurrentThread == handshakeThread)
                    {
                        handshakeThread = null;
                        Monitor.Exit(handshakeLock);
                    }
                }
            }

            if (GetMessage(request).Oneway.GetValueOrDefault())
            {
                t.LockChannel();
                try
                {
                    IList <MemoryStream> bytes = request.GetBytes(Local, this);
                    t.WriteBuffers(bytes);
                    if (callback != null)
                    {
                        callback.HandleResult(default(T));
                    }
                }
                finally
                {
                    t.UnlockChannel();
                }
            }
            else
            {
                IList <MemoryStream> bytes = request.GetBytes(Local, this);
                var transceiverCallback    = new TransceiverCallback <T>(this, request, callback, Local);

                t.Transceive(bytes, transceiverCallback);

                //if (Thread.CurrentThread == handshakeThread)
                //{
                //    Monitor.Exit(handshakeLock);
                //}
            }
        }
예제 #2
0
파일: Requestor.cs 프로젝트: cunchy0/avro-1
        //    public void Request<TSpecificRecord, TCallback>(String messageName, Object request, ICallback<TCallback> callback)
        //where TCallback : class
        //where TSpecificRecord : class, ISpecificRecord
        public void Request <T>(String messageName, Object request, ICallback <T> callback)
        {
            var rpcRequest = new RpcRequest(messageName, request, new RpcContext());

            Request(rpcRequest, callback);
        }
예제 #3
0
파일: Requestor.cs 프로젝트: cunchy0/avro-1
 public Response(Requestor requestor, RpcRequest request, BinaryDecoder input)
 {
     this.requestor = requestor;
     this.request   = request;
     this.input     = input;
 }
예제 #4
0
파일: Requestor.cs 프로젝트: cunchy0/avro-1
 private Message GetMessage(RpcRequest request)
 {
     return(request.GetMessage(Local));
 }
예제 #5
0
 public RpcRequest(RpcRequest request)
     : this(request.messageName, request.request, request.Context)
 {
 }
예제 #6
0
파일: RpcRequest.cs 프로젝트: jbadorek/avro
 public RpcRequest(RpcRequest request)
     : this(request.messageName, request.request, request.Context)
 {
 }