Search in sources :

Example 6 with ExchangeChannel

use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.

the class PerformanceServerTest method statServer.

private static ExchangeServer statServer() throws Exception {
    final int port = PerformanceUtils.getIntProperty("port", 9911);
    final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER);
    final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
    final String threadpool = PerformanceUtils.getProperty(Constants.THREADPOOL_KEY, Constants.DEFAULT_THREADPOOL);
    final int threads = PerformanceUtils.getIntProperty(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    final int iothreads = PerformanceUtils.getIntProperty(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS);
    final int buffer = PerformanceUtils.getIntProperty(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    final String channelHandler = PerformanceUtils.getProperty(Constants.DISPATCHER_KEY, ExecutionDispatcher.NAME);
    // 启动服务器
    ExchangeServer server = Exchangers.bind("exchange://0.0.0.0:" + port + "?transporter=" + transporter + "&serialization=" + serialization + "&threadpool=" + threadpool + "&threads=" + threads + "&iothreads=" + iothreads + "&buffer=" + buffer + "&channel.handler=" + channelHandler, new ExchangeHandlerAdapter() {

        public String telnet(Channel channel, String message) throws RemotingException {
            return "echo: " + message + "\r\ntelnet> ";
        }

        public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
            if ("environment".equals(request)) {
                return PerformanceUtils.getEnvironment();
            }
            if ("scene".equals(request)) {
                List<String> scene = new ArrayList<String>();
                scene.add("Transporter: " + transporter);
                scene.add("Service Threads: " + threads);
                return scene;
            }
            return request;
        }
    });
    return server;
}
Also used : ExchangeHandlerAdapter(com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with ExchangeChannel

use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.

the class Main method startServer.

private static void startServer(int port) throws Exception {
    ReplierDispatcher dispatcher = new ReplierDispatcher();
    dispatcher.addReplier(RpcMessage.class, new RpcMessageHandler());
    dispatcher.addReplier(Object.class, new Replier<Object>() {

        public Object reply(ExchangeChannel channel, Object msg) {
            for (int i = 0; i < 10000; i++) System.currentTimeMillis();
            System.out.println("handle:" + msg + ";thread:" + Thread.currentThread().getName());
            return new StringMessage("hello world");
        }
    });
    Exchangers.bind(URL.valueOf("dubbo://localhost:" + port), dispatcher);
}
Also used : ReplierDispatcher(com.alibaba.dubbo.remoting.exchange.support.ReplierDispatcher) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel)

Example 8 with ExchangeChannel

use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.

the class NettyClientTest method main.

public static void main(String[] args) throws RemotingException, InterruptedException {
    ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty&heartbeat=1000"));
    Thread.sleep(60 * 1000 * 50);
}
Also used : ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel)

Example 9 with ExchangeChannel

use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.

the class HeaderExchangeHandler method connected.

public void connected(Channel channel) throws RemotingException {
    channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
    channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
    ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
    try {
        handler.connected(exchangeChannel);
    } finally {
        HeaderExchangeChannel.removeChannelIfDisconnected(channel);
    }
}
Also used : ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel)

Example 10 with ExchangeChannel

use of com.alibaba.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.

the class HeaderExchangeHandler method disconnected.

public void disconnected(Channel channel) throws RemotingException {
    channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
    channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
    ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
    try {
        handler.disconnected(exchangeChannel);
    } finally {
        HeaderExchangeChannel.removeChannelIfDisconnected(channel);
    }
}
Also used : ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel)

Aggregations

ExchangeChannel (com.alibaba.dubbo.remoting.exchange.ExchangeChannel)19 Request (com.alibaba.dubbo.remoting.exchange.Request)6 Channel (com.alibaba.dubbo.remoting.Channel)4 RemotingException (com.alibaba.dubbo.remoting.RemotingException)4 Response (com.alibaba.dubbo.remoting.exchange.Response)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ExchangeServer (com.alibaba.dubbo.remoting.exchange.ExchangeServer)3 HeaderExchangeHandler (com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)3 ExecutionException (com.alibaba.dubbo.remoting.ExecutionException)2 ExchangeHandler (com.alibaba.dubbo.remoting.exchange.ExchangeHandler)2 ExchangeHandlerAdapter (com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 URL (com.alibaba.dubbo.common.URL)1 Page (com.alibaba.dubbo.container.page.Page)1 ExchangeClient (com.alibaba.dubbo.remoting.exchange.ExchangeClient)1 ResponseFuture (com.alibaba.dubbo.remoting.exchange.ResponseFuture)1 ReplierDispatcher (com.alibaba.dubbo.remoting.exchange.support.ReplierDispatcher)1 Date (java.util.Date)1