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