Skip to content

Commit

Permalink
added redisson client shutdown options
Browse files Browse the repository at this point in the history
Overloaded shutdown method to allow specifying the timeout and the
quiet period.
  • Loading branch information
jackygurui committed Apr 27, 2016
1 parent 2e45721 commit 2718f70
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/redisson/Redisson.java
Expand Up @@ -75,6 +75,7 @@
import org.redisson.core.RTopic;

import io.netty.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
* Main infrastructure class allows to get access
Expand Down Expand Up @@ -524,6 +525,12 @@ public RBatch createBatch() {
public void shutdown() {
connectionManager.shutdown();
}


@Override
public void shutdown(long quietPeriod, long timeout, TimeUnit unit) {
connectionManager.shutdown(quietPeriod, timeout, unit);
}

@Override
public Config getConfig() {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/redisson/RedissonClient.java
Expand Up @@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.redisson.client.codec.Codec;
import org.redisson.core.ClusterNode;
Expand Down Expand Up @@ -619,8 +620,24 @@ public interface RedissonClient {

/**
* Shuts down Redisson instance <b>NOT</b> Redis server
*
* This equates to invoke shutdown(2, 15, TimeUnit.SECONDS);
*/
void shutdown();

/**
* Shuts down Redisson instance <b>NOT</b> Redis server
*
* Shutdown ensures that no tasks are submitted for <i>'the quiet period'</i>
* (usually a couple seconds) before it shuts itself down. If a task is submitted during the quiet period,
* it is guaranteed to be accepted and the quiet period will start over.
*
* @param quietPeriod the quiet period as described in the documentation
* @param timeout the maximum amount of time to wait until the executor is {@linkplain #shutdown()}
* regardless if a task was submitted during the quiet period
* @param unit the unit of {@code quietPeriod} and {@code timeout}
*/
void shutdown(long quietPeriod, long timeout, TimeUnit unit);

/**
* Allows to get configuration provided
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/redisson/connection/ConnectionManager.java
Expand Up @@ -99,6 +99,8 @@ public interface ConnectionManager {

void shutdown();

void shutdown(long quietPeriod, long timeout, TimeUnit unit);

EventLoopGroup getGroup();

Timeout newTimeout(TimerTask task, long delay, TimeUnit unit);
Expand Down
Expand Up @@ -124,7 +124,7 @@ public boolean cancel() {
private final Map<ClusterSlotRange, MasterSlaveEntry> entries = PlatformDependent.newConcurrentHashMap();

private final Promise<Boolean> shutdownPromise;

private final InfinitySemaphoreLatch shutdownLatch = new InfinitySemaphoreLatch();

private final Set<RedisClientEntry> clients = Collections.newSetFromMap(PlatformDependent.<RedisClientEntry, Boolean>newConcurrentHashMap());
Expand All @@ -137,7 +137,7 @@ public MasterSlaveConnectionManager(MasterSlaveServersConfig cfg, Config config)
this(config);
init(cfg);
}

public MasterSlaveConnectionManager(Config cfg) {
Version.logVersion();

Expand Down Expand Up @@ -189,7 +189,7 @@ public Map<ClusterSlotRange, MasterSlaveEntry> getEntries() {
protected void init(MasterSlaveServersConfig config) {
this.config = config;

int[] timeouts = new int[] {config.getRetryInterval(), config.getTimeout(), config.getReconnectionTimeout()};
int[] timeouts = new int[]{config.getRetryInterval(), config.getTimeout(), config.getReconnectionTimeout()};
Arrays.sort(timeouts);
int minTimeout = timeouts[0];
if (minTimeout % 100 != 0) {
Expand Down Expand Up @@ -609,15 +609,20 @@ public void releaseRead(NodeSource source, RedisConnection connection) {

@Override
public void shutdown() {
shutdown(2, 15, TimeUnit.SECONDS);//default netty value
}

@Override
public void shutdown(long quietPeriod, long timeout, TimeUnit unit) {
shutdownLatch.close();
shutdownPromise.trySuccess(true);
shutdownLatch.awaitUninterruptibly();

for (MasterSlaveEntry entry : entries.values()) {
entry.shutdown();
}
timer.stop();
group.shutdownGracefully().syncUninterruptibly();
group.shutdownGracefully(quietPeriod, timeout, unit).syncUninterruptibly();
}

@Override
Expand Down Expand Up @@ -669,7 +674,7 @@ public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) {
public InfinitySemaphoreLatch getShutdownLatch() {
return shutdownLatch;
}

@Override
public Future<Boolean> getShutdownPromise() {
return shutdownPromise;
Expand Down

0 comments on commit 2718f70

Please sign in to comment.