Ejemplo n.º 1
0
        public Task <RemotingResponse> InvokeAsync(RemotingRequest request, int timeoutMillis)
        {
            EnsureClientStatus();

            request.Type = RemotingRequestType.Async;
            var taskCompletionSource = new TaskCompletionSource <RemotingResponse>();
            var responseFuture       = new ResponseFuture(request, timeoutMillis, taskCompletionSource);

            if (!_responseFutureDict.TryAdd(request.Sequence, responseFuture))
            {
                throw new ResponseFutureAddFailedException(request.Sequence);
            }

            _clientSocket.QueueMessage(RemotingUtil.BuildRequestMessage(request));

            return(taskCompletionSource.Task);
        }
Ejemplo n.º 2
0
        public RemotingResponse InvokeSync(RemotingRequest request, int timeoutMillis)
        {
            var task     = InvokeAsync(request, timeoutMillis);
            var response = task.WaitResult <RemotingResponse>(timeoutMillis + 1000);

            if (response == null)
            {
                if (!task.IsCompleted)
                {
                    throw new RemotingTimeoutException(_serverEndPoint, request, timeoutMillis);
                }
                else if (task.IsFaulted)
                {
                    throw new RemotingRequestException(_serverEndPoint, request, task.Exception);
                }
                else
                {
                    throw new RemotingRequestException(_serverEndPoint, request, "Remoting response is null due to unkown exception.");
                }
            }
            return(response);
        }
Ejemplo n.º 3
0
        public static byte[] BuildRequestMessage(RemotingRequest request)
        {
            byte[] IdBytes;
            byte[] IdLengthBytes;
            ByteUtil.EncodeString(request.Id, out IdLengthBytes, out IdBytes);

            var sequenceBytes     = BitConverter.GetBytes(request.Sequence);
            var codeBytes         = BitConverter.GetBytes(request.Code);
            var typeBytes         = BitConverter.GetBytes(request.Type);
            var createdTimeBytes  = ByteUtil.EncodeDateTime(request.CreatedTime);
            var headerBytes       = HeaderUtil.EncodeHeader(request.Header);
            var headerLengthBytes = BitConverter.GetBytes(headerBytes.Length);

            return(ByteUtil.Combine(
                       IdLengthBytes,
                       IdBytes,
                       sequenceBytes,
                       codeBytes,
                       typeBytes,
                       createdTimeBytes,
                       headerLengthBytes,
                       headerBytes,
                       request.Body));
        }