Search in sources :

Example 1 with ExchangeHandlerAdapter

use of com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter 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 2 with ExchangeHandlerAdapter

use of com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter in project dubbo by alibaba.

the class PerformanceServerTest method statTelnetServer.

private static ExchangeServer statTelnetServer(int port) throws Exception {
    // 启动服务器
    ExchangeServer telnetserver = Exchangers.bind("exchange://0.0.0.0:" + port, new ExchangeHandlerAdapter() {

        public String telnet(Channel channel, String message) throws RemotingException {
            if (message.equals("help")) {
                return "support cmd: \r\n\tstart \r\n\tstop \r\n\tshutdown \r\n\trestart times [alive] [sleep] \r\ntelnet>";
            } else if (message.equals("stop")) {
                logger.info("server closed:" + server);
                server.close();
                return "stop server\r\ntelnet>";
            } else if (message.startsWith("start")) {
                try {
                    restartServer(0, 0, 0);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return "start server\r\ntelnet>";
            } else if (message.startsWith("shutdown")) {
                System.exit(0);
                return "start server\r\ntelnet>";
            } else if (message.startsWith("channels")) {
                return "server.getExchangeChannels():" + server.getExchangeChannels().size() + "\r\ntelnet>";
            } else if (message.startsWith("restart ")) {
                //r times [sleep] r 10 or r 10 100
                String[] args = message.split(" ");
                int times = Integer.parseInt(args[1]);
                int alive = args.length > 2 ? Integer.parseInt(args[2]) : 0;
                int sleep = args.length > 3 ? Integer.parseInt(args[3]) : 100;
                try {
                    restartServer(times, alive, sleep);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return "restart server,times:" + times + " stop alive time: " + alive + ",sleep time: " + sleep + " usage:r times [alive] [sleep] \r\ntelnet>";
            } else {
                return "echo: " + message + "\r\ntelnet> ";
            }
        }
    });
    return telnetserver;
}
Also used : ExchangeHandlerAdapter(com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer)

Example 3 with ExchangeHandlerAdapter

use of com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter in project dubbo by alibaba.

the class AbstractBenchmarkServer method run.

public void run(String[] args) throws Exception {
    if (args == null || args.length != 5) {
        throw new IllegalArgumentException("must give three args: listenPort | maxThreads | responseSize | transporter | serialization");
    }
    int listenPort = Integer.parseInt(args[0]);
    int maxThreads = Integer.parseInt(args[1]);
    final int responseSize = Integer.parseInt(args[2]);
    String transporter = args[3];
    String serialization = args[4];
    System.out.println(dateFormat.format(new Date()) + " ready to start server,listenPort is: " + listenPort + ",maxThreads is:" + maxThreads + ",responseSize is:" + responseSize + " bytes,transporter is:" + transporter + ",serialization is:" + serialization);
    StringBuilder url = new StringBuilder();
    url.append("exchange://0.0.0.0:");
    url.append(listenPort);
    url.append("?transporter=");
    url.append(transporter);
    url.append("&serialization=");
    url.append(serialization);
    url.append("&threads=");
    url.append(maxThreads);
    Exchangers.bind(url.toString(), new ExchangeHandlerAdapter() {

        public Object reply(ExchangeChannel channel, Object message) throws RemotingException {
            // 发送响应
            return new ResponseObject(responseSize);
        }
    });
}
Also used : ExchangeHandlerAdapter(com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter) RemotingException(com.alibaba.dubbo.remoting.RemotingException) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Date(java.util.Date)

Aggregations

ExchangeChannel (com.alibaba.dubbo.remoting.exchange.ExchangeChannel)3 ExchangeHandlerAdapter (com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter)3 ExchangeServer (com.alibaba.dubbo.remoting.exchange.ExchangeServer)2 RemotingException (com.alibaba.dubbo.remoting.RemotingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1