public static void main()

in tchannel-example/src/main/java/com/uber/tchannel/basic/AsyncRequest.java [41:88]


    public static void main(String[] args) throws Exception {
        TChannel server = createServer();
        TChannel client = createClient();

        SubChannel subChannel = client.makeSubChannel("server");

        final long start = System.currentTimeMillis();
        final CountDownLatch done = new CountDownLatch(3);

        TFutureCallback<RawResponse> callback = new TFutureCallback<RawResponse>() {
            @Override
            public void onResponse(RawResponse response) {
                // when using callback, resource associated with response is released by the the TChannel library
                if (!response.isError()) {
                    System.out.println(String.format("Response received: response code: %s, header: %s, body: %s",
                        response.getResponseCode(),
                        response.getHeader(),
                        response.getBody()));
                } else {
                    System.out.println(String.format("Got error response: %s",
                        response.toString()));
                }

                done.countDown();
            }
        };

        // send three requests
        for (int i = 0; i < 3; i++) {
            RawRequest request = new RawRequest.Builder("server", "pong")
                .setHeader("Marco")
                .setBody("Ping!")
                .build();
            TFuture<RawResponse> future = subChannel.send(request,
                InetAddress.getByName(null),
                8888
            );

            future.addCallback(callback);
        }

        done.await();
        System.out.println(String.format("%nTime cost: %dms", System.currentTimeMillis() - start));

        // close channels asynchronously
        server.shutdown(false);
        client.shutdown(false);
    }