protected override void OnReceiveCore( ReceivingContext context, ResponseMessage response, RpcErrorMessage error )
 {
     base.OnReceiveCore( context, response, error );
     this._connectionPool.Return( context.SocketContext );
     context.SessionContext.Dispose();
     // FIXME: Return to buffer pool.
 }
예제 #2
0
        protected virtual void OnReceiveCore( ReceivingContext context, ResponseMessage response, RpcErrorMessage error )
        {
            IResponseHandler handler;
            bool removed;
            try { }
            finally
            {
                removed = this._sessionTable.TryRemove( response.MessageId, out handler );
                this._sessionTableLatch.Signal();
            }

            if ( removed )
            {
                if ( error.IsSuccess )
                {
                    handler.HandleResponse( response, false );
                }
                else
                {
                    handler.HandleError( error, false );
                }
            }
            else
            {
                // TODO: trace unrecognized receive message.
            }
        }
 /// <summary>
 ///		Complete this invocation as success.
 /// </summary>
 /// <param name="response">
 ///		Replied response.
 ///	</param>
 /// <param name="completedSynchronously">
 ///		When operation is completed same thread as initiater then true.
 /// </param>
 public void HandleResponse( ResponseMessage response, bool completedSynchronously )
 {
     try { }
     finally
     {
         this._response = response;
         Thread.MemoryBarrier();
         base.Complete( completedSynchronously );
     }
 }
        /// <summary>
        ///		Deserialize response message from specified buffer.
        /// </summary>
        /// <param name="input">Buffer which stores serialized request/notification stream.</param>
        /// <param name="result">Deserialied packed message will be stored.</param>
        /// <returns>Error information.</returns>
        /// <exception cref="ArgumentNullException">
        ///		<paramref name="input"/> is null.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        ///		Some filters violate contract.
        /// </exception>
        public RpcErrorMessage Deserialize( IEnumerable<byte> input, out ResponseMessage result )
        {
            if ( input == null )
            {
                throw new ArgumentNullException( "input" );
            }

            Contract.EndContractBlock();

            var context = new ResponseMessageDeserializationContext( input, this._maxRequestLength );
            var sequence = context.ReadBytes();

            foreach ( var preDeserializationFilter in this._preDeserializationFilters )
            {
                var processed = preDeserializationFilter.GetFilter().Process( sequence, context );
                if ( !context.SerializationError.IsSuccess )
                {
                    result = default( ResponseMessage );
                    return context.SerializationError;
                }

                if ( processed == null )
                {
                    throw new InvalidOperationException( "Deserialization filter did not return sequence." );
                }

                sequence = processed;
            }

            DeserializeCore( sequence, context );

            if ( !context.SerializationError.IsSuccess )
            {
                result = default( ResponseMessage );
                return context.SerializationError;
            }

            foreach ( var postDeserializationFilter in this._postDeserializationFilters )
            {
                postDeserializationFilter.GetFilter().Process( context );
                if ( !context.SerializationError.IsSuccess )
                {
                    result = default( ResponseMessage );
                    return context.SerializationError;
                }
            }

            if ( !context.Error.IsNil )
            {
                result = new ResponseMessage( context.MessageId, RpcException.FromMessage( context.Error, context.DeserializedResult ) );
            }
            else
            {
                result = new ResponseMessage( context.MessageId, context.DeserializedResult );
            }

            return RpcErrorMessage.Success;
        }