Search in sources :

Example 6 with DefaultFuture

use of org.apache.dubbo.remoting.exchange.support.DefaultFuture in project dubbo by alibaba.

the class WrappedChannelHandler method getPreferredExecutorService.

/**
 * Currently, this method is mainly customized to facilitate the thread model on consumer side.
 * 1. Use ThreadlessExecutor, aka., delegate callback directly to the thread initiating the call.
 * 2. Use shared executor to execute the callback.
 *
 * @param msg
 * @return
 */
public ExecutorService getPreferredExecutorService(Object msg) {
    if (msg instanceof Response) {
        Response response = (Response) msg;
        DefaultFuture responseFuture = DefaultFuture.getFuture(response.getId());
        // a typical scenario is the response returned after timeout, the timeout response may has completed the future
        if (responseFuture == null) {
            return getSharedExecutorService();
        } else {
            ExecutorService executor = responseFuture.getExecutor();
            if (executor == null || executor.isShutdown()) {
                executor = getSharedExecutorService();
            }
            return executor;
        }
    } else {
        return getSharedExecutorService();
    }
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) ExecutorService(java.util.concurrent.ExecutorService) DefaultFuture(org.apache.dubbo.remoting.exchange.support.DefaultFuture)

Aggregations

DefaultFuture (org.apache.dubbo.remoting.exchange.support.DefaultFuture)6 Request (org.apache.dubbo.remoting.exchange.Request)5 Response (org.apache.dubbo.remoting.exchange.Response)3 URL (org.apache.dubbo.common.URL)2 Channel (org.apache.dubbo.remoting.Channel)2 ChannelBuffer (org.apache.dubbo.remoting.buffer.ChannelBuffer)2 AppResponse (org.apache.dubbo.rpc.AppResponse)2 Demo (org.apache.dubbo.rpc.gen.thrift.Demo)2 RandomAccessByteArrayOutputStream (org.apache.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream)2 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)2 TMessage (org.apache.thrift.protocol.TMessage)2 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)2 TTransport (org.apache.thrift.transport.TTransport)2 Test (org.junit.jupiter.api.Test)2 ExecutorService (java.util.concurrent.ExecutorService)1 RemotingException (org.apache.dubbo.remoting.RemotingException)1 RpcException (org.apache.dubbo.rpc.RpcException)1 TApplicationException (org.apache.thrift.TApplicationException)1