예제 #1
0
  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);
  }
예제 #2
0
 public boolean connect() {
   if (closed.get()) {
     throw new IllegalStateException("Connector closed");
   }
   return client.connect();
 }
예제 #3
0
 public void removeChannelStateListener(ChannelStateListener listener) {
   client.removeChannelStateListener(listener);
 }
예제 #4
0
 public void addChannelStateListener(ChannelStateListener listener) {
   client.addChannelStateListener(listener);
 }
예제 #5
0
 public boolean isConnected() {
   return client.isConnected();
 }
예제 #6
0
 public ChannelFuture closeFuture() {
   return client.closeFuture();
 }