コード例 #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);
        }
コード例 #2
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));
        }