synch graceful exit code

This commit is contained in:
zzz
2016-12-16 18:01:30 +00:00
parent 636badcec2
commit 14a839ebba
2 changed files with 20 additions and 10 deletions

View File

@ -111,13 +111,17 @@ public class ConfigRestartBean {
} }
private static boolean isShuttingDown(RouterContext ctx) { private static boolean isShuttingDown(RouterContext ctx) {
return Router.EXIT_GRACEFUL == ctx.router().scheduledGracefulExitCode() || int code = ctx.router().scheduledGracefulExitCode();
Router.EXIT_HARD == ctx.router().scheduledGracefulExitCode(); return Router.EXIT_GRACEFUL == code ||
Router.EXIT_HARD == code;
} }
private static boolean isRestarting(RouterContext ctx) { private static boolean isRestarting(RouterContext ctx) {
return Router.EXIT_GRACEFUL_RESTART == ctx.router().scheduledGracefulExitCode() || int code = ctx.router().scheduledGracefulExitCode();
Router.EXIT_HARD_RESTART == ctx.router().scheduledGracefulExitCode(); return Router.EXIT_GRACEFUL_RESTART == code ||
Router.EXIT_HARD_RESTART == code;
} }
/** this is for summaryframe.jsp */ /** this is for summaryframe.jsp */
public static long getRestartTimeRemaining() { public static long getRestartTimeRemaining() {
RouterContext ctx = ContextHelper.getContext(null); RouterContext ctx = ContextHelper.getContext(null);

View File

@ -1361,8 +1361,8 @@ public class Router implements RouterClock.ClockShiftListener {
if (isFinalShutdownInProgress()) if (isFinalShutdownInProgress())
return; // too late return; // too late
changeState(State.GRACEFUL_SHUTDOWN); changeState(State.GRACEFUL_SHUTDOWN);
_gracefulExitCode = exitCode;
} }
_gracefulExitCode = exitCode;
//_config.put(PROP_SHUTDOWN_IN_PROGRESS, "true"); //_config.put(PROP_SHUTDOWN_IN_PROGRESS, "true");
_context.throttle().setShutdownStatus(); _context.throttle().setShutdownStatus();
synchronized (_gracefulShutdownDetector) { synchronized (_gracefulShutdownDetector) {
@ -1380,8 +1380,8 @@ public class Router implements RouterClock.ClockShiftListener {
if (isFinalShutdownInProgress()) if (isFinalShutdownInProgress())
return; // too late return; // too late
changeState(State.RUNNING); changeState(State.RUNNING);
_gracefulExitCode = -1;
} }
_gracefulExitCode = -1;
//_config.remove(PROP_SHUTDOWN_IN_PROGRESS); //_config.remove(PROP_SHUTDOWN_IN_PROGRESS);
_context.throttle().cancelShutdownStatus(); _context.throttle().cancelShutdownStatus();
synchronized (_gracefulShutdownDetector) { synchronized (_gracefulShutdownDetector) {
@ -1394,16 +1394,22 @@ public class Router implements RouterClock.ClockShiftListener {
* *
* @return one of the EXIT_* values or -1 * @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? * How long until the graceful shutdown will kill us?
* @return -1 if no shutdown in progress. * @return -1 if no shutdown in progress.
*/ */
public long getShutdownTimeRemaining() { public long getShutdownTimeRemaining() {
if (_gracefulExitCode <= 0) return -1; // maybe Long.MAX_VALUE would be better? synchronized(_stateLock) {
if (_gracefulExitCode == EXIT_HARD || _gracefulExitCode == EXIT_HARD_RESTART) if (_gracefulExitCode <= 0) return -1; // maybe Long.MAX_VALUE would be better?
return 0; if (_gracefulExitCode == EXIT_HARD || _gracefulExitCode == EXIT_HARD_RESTART)
return 0;
}
long exp = _context.tunnelManager().getLastParticipatingExpiration(); long exp = _context.tunnelManager().getLastParticipatingExpiration();
if (exp < 0) if (exp < 0)
return 0; return 0;