Search in sources :

Example 6 with ExchangeServer

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

the class PerformanceServerTest method statTelnetServer.

private static ExchangeServer statTelnetServer(int port) throws Exception {
    // Start server
    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(org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer)

Aggregations

ExchangeServer (org.apache.dubbo.remoting.exchange.ExchangeServer)6 ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)3 RemotingException (org.apache.dubbo.remoting.RemotingException)2 Transporter (org.apache.dubbo.remoting.Transporter)2 ExchangeHandlerAdapter (org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter)2 RpcException (org.apache.dubbo.rpc.RpcException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ProtocolServer (org.apache.dubbo.rpc.ProtocolServer)1