public boolean isRunning() { if (hasStarted.isDone()) { try { TimeUnit.MILLISECONDS.sleep(500); } catch (InterruptedException e) { logger.trace("Exception while waiting for the proxy to confirm running status", e); } return !bossGroup.isShuttingDown() && !workerGroup.isShuttingDown(); } else { return false; } }
private void tryReconnect( final EventLoopGroup group, final RedisConnection connection, final int attempts) { if (connection.isClosed() || group.isShuttingDown()) { return; } log.debug( "reconnecting {} to {} ", connection, connection.getRedisClient().getAddr(), connection); bootstrap .connect() .addListener( new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture future) throws Exception { if (connection.isClosed() || group.isShuttingDown()) { return; } try { if (future.isSuccess()) { log.debug( "{} connected to {}", connection, connection.getRedisClient().getAddr()); reconnect(connection, future.channel()); return; } } catch (RedisException e) { log.warn( "Can't connect " + connection + " to " + connection.getRedisClient().getAddr(), e); } int timeout = 2 << attempts; group.schedule( new Runnable() { @Override public void run() { tryReconnect(group, connection, Math.min(BACKOFF_CAP, attempts + 1)); } }, timeout, TimeUnit.MILLISECONDS); } }); }