コード例 #1
0
ファイル: Requestor.cs プロジェクト: cunchy0/avro-1
            public void HandleResult(IList <MemoryStream> result)
            {
                var bbi   = new ByteBufferInputStream(result);
                var input = new BinaryDecoder(bbi);

                if (!requestor.ReadHandshake(input))
                {
                    // Resend the handshake and return
                    var handshake = new RpcRequest(request);

                    IList <MemoryStream> requestBytes = handshake.GetBytes(requestor.Local, requestor);
                    var transceiverCallback           = new TransceiverCallback <T>(requestor, handshake, callback,
                                                                                    local);

                    requestor.Transceiver.Transceive(requestBytes, transceiverCallback);
                    return;
                }

                // Read response; invoke callback
                var response = new Response(requestor, request, input);

                try
                {
                    Object responseObject;
                    try
                    {
                        responseObject = response.getResponse();
                    }
                    catch (Exception e)
                    {
                        if (callback != null)
                        {
                            callback.HandleException(e);
                        }
                        return;
                    }
                    if (callback != null)
                    {
                        callback.HandleResult((T)responseObject);
                    }
                }
                catch
                {
                    //LOG.error("Error in callback handler: " + t, t);
                }
            }
コード例 #2
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);
                //}
            }
        }