int port = Integer.parseInt(args[1]);
PeerInfo serverInfo = new PeerInfo(args[0], port);
//You need then to create a DuplexTcpServerBootstrap and provide it an RpcCallExecutor.
DuplexTcpServerBootstrap bootstrap = new DuplexTcpServerBootstrap(
serverInfo,
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool())
);
bootstrap.setRpcServerCallExecutor(new ThreadPoolCallExecutor(10, 10));
// set up request logging
// final CategoryPerServiceLogger logPolicy = new CategoryPerServiceLogger();
// logPolicy.setLogRequestProto(true);
// logPolicy.setLogResponseProto(true);
// bootstrap.setLogger(logPolicy);
//Finally binding the bootstrap to the TCP port will start off the socket accepting and clients can start to connect.
long serverId = new SecureRandom().nextLong();
String zk_str = props.getProperty("zookeeper.connection.string", ZK_CONNECT_STRING);
if (args.length == 3) {
zk_str = args[2];
}
List<Client.HostPort> addresses = Lists.newArrayList();
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface ifc = networkInterfaces.nextElement();
if (!ifc.isLoopback()) {
for (InterfaceAddress address : ifc.getInterfaceAddresses()) {
addresses.add(new Client.HostPort(address.getAddress().getHostAddress(), port));
}
}
}
ClusterState zkState = new ClusterState(zk_str, FRANZ_BASE, new Info(serverId, addresses));
bootstrap.getRpcServiceRegistry().registerBlockingService(Catcher.CatcherService.newReflectiveBlockingService(new com.mapr.franz.server.CatcherServiceImpl(serverId, zkState)));
//If you want to track the RPC peering events with clients, use a RpcClientConnectionRegistry or a TcpConnectionEventListener for TCP connection events. This is the mechanism you can use to "discover" RPC clients before they "call" any service.
TcpConnectionEventListener listener = new TcpConnectionEventListener() {
@Override
public void connectionClosed(RpcClientChannel clientChannel) {
log.debug("Disconnect from {}", clientChannel.getPeerInfo());
}
@Override
public void connectionOpened(RpcClientChannel clientChannel) {
log.debug("Connect with {}", clientChannel.getPeerInfo());
}
};
bootstrap.registerConnectionEventListener(listener);
bootstrap.bind();
}