mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
Fix server mode: now all listener threads are daemon, avoid main thread exit and add a shutdown hook
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@594 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
bcb690da7f
commit
1ab20897af
@ -13,11 +13,8 @@ import davmail.ui.tray.DavGatewayTray;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.log4j.FileAppender;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
@ -28,6 +25,8 @@ import java.util.ArrayList;
|
||||
public class DavGateway {
|
||||
private static final String HTTP_DAVMAIL_SOURCEFORGE_NET_VERSION_TXT = "http://davmail.sourceforge.net/version.txt";
|
||||
|
||||
private static boolean stopped;
|
||||
|
||||
private DavGateway() {
|
||||
}
|
||||
|
||||
@ -48,6 +47,30 @@ public class DavGateway {
|
||||
DavGatewayTray.init();
|
||||
|
||||
start();
|
||||
|
||||
// server mode: all threads are daemon threads, do not let main stop
|
||||
if (Settings.getBooleanProperty("davmail.server")) {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_INTERRUPTED"));
|
||||
DavGateway.stop();
|
||||
DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_STOP"));
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
while (!stopped) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_INTERRUPTED"));
|
||||
stop();
|
||||
DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_STOP"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void start() {
|
||||
|
@ -105,6 +105,8 @@ LOG_READ_CLIENT_LOGIN=< LOGIN ********
|
||||
LOG_READ_CLIENT_PASS=< PASS ********
|
||||
LOG_READ_CLIENT_PASSWORD=< ********
|
||||
LOG_REPORT_EVENT=Report event {0}/{1}
|
||||
LOG_GATEWAY_INTERRUPTED=Stopping DavMail gateway
|
||||
LOG_GATEWAY_STOP=DavMail gateway stopped
|
||||
LOG_SEARCHING_CALENDAR_EVENTS=Searching calendar events at {0} ...
|
||||
LOG_SEARCHING_CALENDAR_MESSAGES=Searching calendar messages...
|
||||
LOG_SEARCH_QUERY=Search: {0}
|
||||
|
@ -222,3 +222,5 @@ UI_PKCS11_CONFIG_HELP=Configuration PKCS11 compl
|
||||
UI_PKCS11_CONFIG=Configuration PKCS11
|
||||
UI_CLIENT_CERTIFICATE=Certificat client
|
||||
UI_LOG_FILE_PATH=Chemin du fichier de traces :
|
||||
LOG_GATEWAY_INTERRUPTED=Arrêt de la passerelle DavMail en cours
|
||||
LOG_GATEWAY_STOP=Passerelle DavMail arrêtée
|
Loading…
x
Reference in New Issue
Block a user