
pl.chilldev.commons.daemon.lifecycle.Runner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-daemon Show documentation
Show all versions of commons-daemon Show documentation
Helper components for handling daemon services with Apache Commons Daemon.
/**
* This file is part of the ChillDev-Commons.
*
* @license http://mit-license.org/ The MIT license
* @copyright 2014 - 2015 © by Rafał Wrzeszcz - Wrzasq.pl.
*/
package pl.chilldev.commons.daemon.lifecycle;
// dependencies and sub-modules
import org.apache.commons.daemon.Daemon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Handles application shutdown.
*/
public class Runner extends Thread
{
/**
* Logger.
*/
private Logger logger = LoggerFactory.getLogger(Runner.class);
/**
* Runs application.
*
*
* This method runs application directly by invoking Apache Commons Daemon flow.
*
*
*
* Standard usage is just `(new Runner()).run(new ChillDevApplication())`.
*
*
* @param daemon Daemon application.
*/
public void run(Daemon daemon)
{
try {
// perform initialization and start daemon
daemon.init(null);
daemon.start();
// schedule shutdown hook for daemon cleanup
Runtime.getRuntime().addShutdownHook(new Shutdown(daemon));
//CHECKSTYLE:OFF: IllegalCatchCheck
} catch (Throwable error) {
//CHECKSTYLE:ON: IllegalCatchCheck
this.logger.error("Fatal error {}.", error.getMessage(), error);
throw new RuntimeException(
String.format("Fatal error: %s", error.getMessage()),
error
);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy