Fix Winrun4J service wrapper implementation, launch a non daemon thread

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1988 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2012-08-22 20:14:46 +00:00
parent 43356e24ff
commit e59e4d526f
2 changed files with 26 additions and 3 deletions

View File

@ -191,7 +191,9 @@ public final class Settings {
String logFilePath = Settings.getProperty("davmail.logFilePath");
// set default log file path
if ((logFilePath == null || logFilePath.length() == 0)) {
if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
if (Settings.getBooleanProperty("davmail.server")) {
logFilePath = "davmail.log";
} else if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
// store davmail.log in OSX Logs directory
logFilePath = System.getProperty("user.home") + "/Library/Logs/DavMail/davmail.log";
} else {
@ -231,7 +233,7 @@ public final class Settings {
/**
* Update Log4J config from settings.
*/
private static void updateLoggingConfig() {
public static void updateLoggingConfig() {
String logFilePath = getLogFilePath();
Logger rootLogger = Logger.getRootLogger();

View File

@ -30,6 +30,8 @@ import org.boris.winrun4j.ServiceException;
*/
public class DavService extends AbstractService {
protected boolean stopped;
/**
* Perform a service request.
*
@ -44,6 +46,7 @@ public class DavService extends AbstractService {
case SERVICE_CONTROL_SHUTDOWN:
DavGatewayTray.debug(new BundleMessage("LOG_STOPPING_DAVMAIL"));
DavGateway.stop();
stopped = true;
}
return 0;
}
@ -61,11 +64,29 @@ public class DavService extends AbstractService {
}
Settings.load();
DavGatewayTray.init();
if (!Settings.getBooleanProperty("davmail.server")) {
Settings.setProperty("davmail.server", "true");
Settings.updateLoggingConfig();
}
DavGateway.start();
DavGatewayTray.debug(new BundleMessage("LOG_DAVMAIL_STARTED"));
// launch a non daemon thread
Thread shutdownListenerThread = new Thread("ShutDownListener") {
public void run() {
try {
while (!stopped) {
Thread.sleep(1000);
}
} catch (InterruptedException e) {
DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_INTERRUPTED"));
DavGateway.stop();
DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_STOP"));
}
}
};
shutdownListenerThread.start();
return 0;
}
}