Search in sources :

Example 1 with HeaderExchangeServer

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

the class HeartbeatServer method main.

public static void main(String[] args) throws Exception {
    final HeartBeatExchangeHandler serverHandler = new HeartBeatExchangeHandler(handler);
    Thread serverThread = new Thread(new Runnable() {

        public void run() {
            try {
                exchangeServer = new HeaderExchangeServer(Transporters.bind(clientUrl.addParameter(Constants.HEARTBEAT_KEY, 1000), serverHandler));
                serverStarted = true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    serverThread.setDaemon(true);
    serverThread.start();
    while (!serverStarted) {
        Thread.sleep(1000);
    }
    HeartBeatExchangeHandler clientHandler = new HeartBeatExchangeHandler(handler);
    ExchangeClient exchangeClient = new HeaderExchangeClient(Transporters.connect(clientUrl, clientHandler));
    for (int i = 0; i < 10; i++) {
        Thread.sleep(1000);
        System.out.print(".");
    }
    System.out.println();
    if (clientHandler.getHeartBeatCount() > 0) {
        System.out.printf("Client receives %d heartbeats", clientHandler.getHeartBeatCount());
    } else {
        throw new Exception("Server heartbeat does not work.");
    }
    exchangeClient.close();
    exchangeServer.close();
}
Also used : HeaderExchangeClient(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeClient) ExchangeClient(com.alibaba.dubbo.remoting.exchange.ExchangeClient) HeaderExchangeClient(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeClient) HeaderExchangeServer(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeServer)

Example 2 with HeaderExchangeServer

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

the class HeartbeatClient method main.

public static void main(String[] args) throws Exception {
    final HeartBeatExchangeHandler serverHandler = new HeartBeatExchangeHandler(handler);
    Thread serverThread = new Thread(new Runnable() {

        public void run() {
            try {
                exchangeServer = new HeaderExchangeServer(Transporters.bind(serverUrl, serverHandler));
                serverStarted = true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    serverThread.setDaemon(true);
    serverThread.start();
    while (!serverStarted) {
        Thread.sleep(1000);
    }
    URL url = serverUrl.addParameter(Constants.HEARTBEAT_KEY, 1000);
    HeartBeatExchangeHandler clientHandler = new HeartBeatExchangeHandler(handler);
    ExchangeClient exchangeClient = new HeaderExchangeClient(Transporters.connect(url, clientHandler));
    for (int i = 0; i < 10; i++) {
        Thread.sleep(1000);
        System.out.print(".");
    }
    System.out.println();
    if (serverHandler.getHeartBeatCount() > 0) {
        System.out.printf("Server receives %d heartbeats", serverHandler.getHeartBeatCount());
    } else {
        throw new Exception("Client heartbeat does not work.");
    }
    exchangeClient.close();
    exchangeServer.close();
}
Also used : HeaderExchangeClient(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeClient) ExchangeClient(com.alibaba.dubbo.remoting.exchange.ExchangeClient) HeaderExchangeClient(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeClient) HeaderExchangeServer(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeServer) URL(com.alibaba.dubbo.common.URL)

Aggregations

ExchangeClient (com.alibaba.dubbo.remoting.exchange.ExchangeClient)2 HeaderExchangeClient (com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeClient)2 HeaderExchangeServer (com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeServer)2 URL (com.alibaba.dubbo.common.URL)1