RedisProcess.restart method added

pull/1888/head
Nikita Koksharov 6 years ago
parent a44d4a7124
commit d70aa0fc13

@ -16,6 +16,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.redisson.client.RedisClient;
@ -241,7 +242,7 @@ public class RedisRunner {
String line;
try {
while (p.isAlive() && (line = reader.readLine()) != null && !RedissonRuntimeEnvironment.isTravis) {
System.out.println("REDIS PROCESS: " + line);
// System.out.println("REDIS PROCESS: " + line);
}
} catch (IOException ex) {
System.out.println("Exception: " + ex.getLocalizedMessage());
@ -878,7 +879,7 @@ public class RedisRunner {
public static final class RedisProcess {
private final Process redisProcess;
private Process redisProcess;
private final RedisRunner runner;
private RedisVersion redisVersion;
@ -887,6 +888,40 @@ public class RedisRunner {
this.runner = runner;
}
public void restart(int startTimeout) {
if (runner.isNosave() && !runner.isRandomDir()) {
RedisClient c = createDefaultRedisClientInstance();
RedisConnection connection = c.connect();
try {
connection.async(new RedisStrictCommand<Void>("SHUTDOWN", "NOSAVE", new VoidReplayConvertor()))
.await(3, TimeUnit.SECONDS);
} catch (InterruptedException interruptedException) {
//shutdown via command failed, lets wait and kill it later.
}
c.shutdown();
connection.closeAsync().syncUninterruptibly();
}
Process p = redisProcess;
p.destroy();
boolean normalTermination = false;
try {
normalTermination = p.waitFor(5, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
//OK lets hurry up by force kill;
}
if (!normalTermination) {
p = p.destroyForcibly();
}
Executors.newScheduledThreadPool(1).schedule(() -> {
try {
redisProcess = runner.run().redisProcess;
} catch (Exception e) {
e.printStackTrace();
}
}, startTimeout, TimeUnit.SECONDS);
}
public int stop() {
if (runner.isNosave() && !runner.isRandomDir()) {
RedisClient c = createDefaultRedisClientInstance();

Loading…
Cancel
Save