Ensure that context is destroyed on restart

This commit is contained in:
René Pfeuffer
2020-03-25 16:52:53 +01:00
parent 15aab3059d
commit 24c7cb0b67
6 changed files with 57 additions and 31 deletions

View File

@@ -35,7 +35,7 @@ import java.util.function.IntConsumer;
* <p>
* This is useful if an external mechanism is able to restart the process after it has exited.
*/
class ExitRestartStrategy implements RestartStrategy {
class ExitRestartStrategy extends RestartStrategy {
private static final Logger LOG = LoggerFactory.getLogger(ExitRestartStrategy.class);
@@ -45,6 +45,8 @@ class ExitRestartStrategy implements RestartStrategy {
private IntConsumer exiter = System::exit;
private int exitCode;
ExitRestartStrategy() {
}
@@ -54,12 +56,12 @@ class ExitRestartStrategy implements RestartStrategy {
}
@Override
public void restart(InjectionContext context) {
int exitCode = determineExitCode();
LOG.warn("destroy injection context");
context.destroy();
public void prepareRestart(InjectionContext context) {
exitCode = determineExitCode();
}
@Override
protected void executeRestart(InjectionContext context) {
LOG.warn("exit scm-manager with exit code {}", exitCode);
exiter.accept(exitCode);
}