Skip to content

Commit

Permalink
Merge pull request #35 from tomtom-international/feature/shutdown-delay
Browse files Browse the repository at this point in the history
feat: add configurable shutdown delay
  • Loading branch information
kiwisCoding authored Nov 18, 2020
2 parents 635c2c1 + 1a641ec commit 8385102
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ example of core settings configuration:
quiet: true # Don't print out ASCII banner at the start (default: false)
logLevel: trace # Level of James logs - trace|debug|info|warn|error|fatal
# (default: warn)
shutdownDelay: 500 # Shutdown hook delay in ms make possible to capture closing events
# default: 1000

plugins:
includeDirectories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
package com.tomtom.james.agent;

import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Uninterruptibles;
import com.tomtom.james.common.api.Closeable;
import com.tomtom.james.common.api.publisher.EventPublisher;
import com.tomtom.james.common.api.script.ScriptEngine;
import com.tomtom.james.common.log.Logger;
import com.tomtom.james.configuration.AgentConfiguration;
import com.tomtom.james.newagent.MethodExecutionContextHelper;

import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class ShutdownHook extends Thread {

Expand All @@ -50,6 +50,7 @@ public ShutdownHook(ControllersManager controllersManager,

@Override
public void run() {
Uninterruptibles.sleepUninterruptibly(agentConfiguration.getShutdownDelay(), TimeUnit.MILLISECONDS);
closeables.forEach(Closeable::close);
if (!agentConfiguration.isQuiet()) {
LOG.info("Agent shutdown complete.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ public interface AgentConfiguration {

boolean isQuiet();
Logger.Level getLogLevel();
Integer getShutdownDelay();

}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public boolean isQuiet() {
.orElse(false);
}

@Override
public Integer getShutdownDelay() {
return configuration.get("shutdownDelay")
.map(StructuredConfiguration::asInteger)
.orElse(1000);
}

@Override
public Logger.Level getLogLevel() {
return configuration.get("logLevel")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public int getAsyncWorkers() {
public int getMaxAsyncJobQueueCapacity() {
return structuredConfiguration.get("maxAsyncJobQueueCapacity")
.map(StructuredConfiguration::asInteger)
.orElse(10_000);
.orElse(16_384);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ShutdownHookSpec extends Specification {

def "Should close resources on execution"() {
when:
agentConfiguration.getShutdownDelay() >> 1
shutdownHook.run()

then:
Expand Down

0 comments on commit 8385102

Please sign in to comment.