From 14a839ebba6a50bd53d31c9259d5a9847cf2b2d7 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 16 Dec 2016 18:01:30 +0000 Subject: [PATCH] synch graceful exit code --- .../net/i2p/router/web/ConfigRestartBean.java | 12 ++++++++---- router/java/src/net/i2p/router/Router.java | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigRestartBean.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigRestartBean.java index 6e506422ce..e511511c51 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigRestartBean.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigRestartBean.java @@ -111,13 +111,17 @@ public class ConfigRestartBean { } private static boolean isShuttingDown(RouterContext ctx) { - return Router.EXIT_GRACEFUL == ctx.router().scheduledGracefulExitCode() || - Router.EXIT_HARD == ctx.router().scheduledGracefulExitCode(); + int code = ctx.router().scheduledGracefulExitCode(); + return Router.EXIT_GRACEFUL == code || + Router.EXIT_HARD == code; } + private static boolean isRestarting(RouterContext ctx) { - return Router.EXIT_GRACEFUL_RESTART == ctx.router().scheduledGracefulExitCode() || - Router.EXIT_HARD_RESTART == ctx.router().scheduledGracefulExitCode(); + int code = ctx.router().scheduledGracefulExitCode(); + return Router.EXIT_GRACEFUL_RESTART == code || + Router.EXIT_HARD_RESTART == code; } + /** this is for summaryframe.jsp */ public static long getRestartTimeRemaining() { RouterContext ctx = ContextHelper.getContext(null); diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index e80c91237e..26271f10c0 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -1361,8 +1361,8 @@ public class Router implements RouterClock.ClockShiftListener { if (isFinalShutdownInProgress()) return; // too late changeState(State.GRACEFUL_SHUTDOWN); + _gracefulExitCode = exitCode; } - _gracefulExitCode = exitCode; //_config.put(PROP_SHUTDOWN_IN_PROGRESS, "true"); _context.throttle().setShutdownStatus(); synchronized (_gracefulShutdownDetector) { @@ -1380,8 +1380,8 @@ public class Router implements RouterClock.ClockShiftListener { if (isFinalShutdownInProgress()) return; // too late changeState(State.RUNNING); + _gracefulExitCode = -1; } - _gracefulExitCode = -1; //_config.remove(PROP_SHUTDOWN_IN_PROGRESS); _context.throttle().cancelShutdownStatus(); synchronized (_gracefulShutdownDetector) { @@ -1394,16 +1394,22 @@ public class Router implements RouterClock.ClockShiftListener { * * @return one of the EXIT_* values or -1 */ - public int scheduledGracefulExitCode() { return _gracefulExitCode; } + public int scheduledGracefulExitCode() { + synchronized(_stateLock) { + return _gracefulExitCode; + } + } /** * How long until the graceful shutdown will kill us? * @return -1 if no shutdown in progress. */ public long getShutdownTimeRemaining() { - if (_gracefulExitCode <= 0) return -1; // maybe Long.MAX_VALUE would be better? - if (_gracefulExitCode == EXIT_HARD || _gracefulExitCode == EXIT_HARD_RESTART) - return 0; + synchronized(_stateLock) { + if (_gracefulExitCode <= 0) return -1; // maybe Long.MAX_VALUE would be better? + if (_gracefulExitCode == EXIT_HARD || _gracefulExitCode == EXIT_HARD_RESTART) + return 0; + } long exp = _context.tunnelManager().getLastParticipatingExpiration(); if (exp < 0) return 0; -- GitLab