/** Close the connection. */
 public synchronized void close() {
   if (!closed && channel != null) {
     ConnectionWatchdog watchdog = channel.getPipeline().get(ConnectionWatchdog.class);
     watchdog.setReconnect(false);
     closed = true;
     channel.close();
   }
 }
Exemple #2
0
  private <K, V, T extends RedisAsyncConnection<K, V>> T connect(
      CommandHandler<K, V> handler, T connection) {
    try {
      ConnectionWatchdog watchdog = new ConnectionWatchdog(bootstrap, channels, timer);
      ChannelPipeline pipeline = Channels.pipeline(watchdog, handler, connection);
      Channel channel = bootstrap.getFactory().newChannel(pipeline);

      ChannelFuture future = channel.connect((SocketAddress) bootstrap.getOption("remoteAddress"));
      future.await();

      if (!future.isSuccess()) {
        throw future.getCause();
      }

      watchdog.setReconnect(true);

      return connection;
    } catch (Throwable e) {
      throw new RedisException("Unable to connect", e);
    }
  }