Skip to content

Commit

Permalink
Improved shutdown behaviour of MQTT image.
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Jul 26, 2018
1 parent 8af76b9 commit d842cf4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion FROST-Server.MQTT/Dockerfile
Expand Up @@ -7,4 +7,4 @@ EXPOSE 9876
ARG JAR_FILE
ADD target/${JAR_FILE} /usr/local/FROST/FROST-Mqtt.jar
WORKDIR /usr/local/FROST
CMD java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -jar FROST-Mqtt.jar
CMD ["java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-jar", "FROST-Mqtt.jar"]
Expand Up @@ -43,12 +43,28 @@ public class FrostMqttServer {
private static final String KEY_WAIT_FOR_ENTER = "WaitForEnter";
private static final String CONFIG_FILE_NAME = "FrostMqtt.properties";
private final CoreSettings coreSettings;
private Thread shutdownHook;

public FrostMqttServer(CoreSettings coreSettings) {
this.coreSettings = coreSettings;
}

private synchronized void addShutdownHook() {
if (this.shutdownHook == null) {
this.shutdownHook = new Thread(() -> {
LOGGER.info("Shutting down...");
try {
stop();
} catch (Exception ex) {
LOGGER.warn("Exception stopping listeners.", ex);
}
});
Runtime.getRuntime().addShutdownHook(shutdownHook);
}
}

public void start() {
addShutdownHook();
PersistenceManagerFactory.init(coreSettings);
MessageBusFactory.init(coreSettings);
MqttManager.init(coreSettings);
Expand Down

0 comments on commit d842cf4

Please sign in to comment.