Beispiel #1
0
 /**
  * Shutdown this client and close all open connections. The client should be discarded after
  * calling shutdown.
  */
 public void shutdown() {
   for (Channel c : channels) {
     ChannelPipeline pipeline = c.getPipeline();
     RedisAsyncConnection<?, ?> connection = pipeline.get(RedisAsyncConnection.class);
     connection.close();
   }
   ChannelGroupFuture future = channels.close();
   future.awaitUninterruptibly();
   bootstrap.releaseExternalResources();
 }
Beispiel #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);
    }
  }