public Connector( SocketAddress remoteAddress, TimeProperty autoReconnectInterval, MessageEncodingProtocol messageEncodingProtocol) { this.remoteAddress = remoteAddress; loopGroup = new MessageQueueLoopGroup( Executors.newCachedThreadPool(), messageHandler, new SingleMessageQueueStrategy(), new LoopShiftingStrategy()); client = new NetLightClient(remoteAddress, getSslContext(), messageEncodingProtocol, loopGroup); if (autoReconnectInterval != null) { client.addChannelStateListener( new AutoReconnector(autoReconnectInterval.to(TimeUnit.MILLISECONDS))); } clientHandler = (ClientHandler) client.getChannelInitializer().getTcpChannelInitializer().getChannelHandler(); serverSentMessageNotifier = new EventNotifier<>( new EventNotifierHandler<Message, ServerSentMessageListener>() { @Override public void handle(Message message, ServerSentMessageListener listener) { listener.onMessage(message); } @Override public void exceptionCaught(Throwable cause) { serverSentMessageNotifier.start(); } }, Message.class); }
public void addChannelStateListener(ChannelStateListener listener) { client.addChannelStateListener(listener); }