Пример #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();
 }