public class NorbertJavaNetworkClientMain {
public static void main(String[] args) {
InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
ClusterClient cc = new ZooKeeperClusterClient(args[0], args[1], 30000);
NetworkClientConfig config = new NetworkClientConfig();
config.setClusterClient(cc);
NetworkClient nc = new NettyNetworkClient(config, new RoundRobinLoadBalancerFactory());
// PartitionedNetworkClient<Integer> nc = new NettyPartitionedNetworkClient<Integer>(config, new IntegerConsistentHashPartitionedLoadBalancerFactory());
nc.registerRequest(NorbertExampleProtos.Ping.getDefaultInstance(), NorbertExampleProtos.PingResponse.getDefaultInstance());
Node node = cc.getNodeWithId(1);
Future<Message> f = nc.sendMessageToNode(NorbertExampleProtos.Ping.newBuilder().setTimestamp(System.currentTimeMillis()).build(), node);
try {
NorbertExampleProtos.PingResponse response = (NorbertExampleProtos.PingResponse) f.get(750, TimeUnit.MILLISECONDS);
System.out.println(String.format("Ping took %dms", System.currentTimeMillis() - response.getTimestamp()));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
cc.shutdown();
}