Check for released version in a separate thread and set timeout to ten seconds
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@832 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
1a78128a09
commit
3b6cd4f8ba
|
@ -31,6 +31,7 @@ import davmail.ui.tray.DavGatewayTray;
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -41,6 +42,7 @@ import java.util.ArrayList;
|
||||||
* DavGateway main class
|
* DavGateway main class
|
||||||
*/
|
*/
|
||||||
public final class DavGateway {
|
public final class DavGateway {
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(DavGateway.class);
|
||||||
private static final String HTTP_DAVMAIL_SOURCEFORGE_NET_VERSION_TXT = "http://davmail.sourceforge.net/version.txt";
|
private static final String HTTP_DAVMAIL_SOURCEFORGE_NET_VERSION_TXT = "http://davmail.sourceforge.net/version.txt";
|
||||||
|
|
||||||
private static boolean stopped;
|
private static boolean stopped;
|
||||||
|
@ -138,18 +140,24 @@ public final class DavGateway {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String currentVersion = getCurrentVersion();
|
final String currentVersion = getCurrentVersion();
|
||||||
DavGatewayTray.info(new BundleMessage("LOG_DAVMAIL_GATEWAY_LISTENING",
|
DavGatewayTray.info(new BundleMessage("LOG_DAVMAIL_GATEWAY_LISTENING",
|
||||||
currentVersion == null ? "" : currentVersion, messages));
|
currentVersion == null ? "" : currentVersion, messages));
|
||||||
if (!errorMessages.isEmpty()) {
|
if (!errorMessages.isEmpty()) {
|
||||||
DavGatewayTray.error(new BundleMessage("LOG_MESSAGE", errorMessages));
|
DavGatewayTray.error(new BundleMessage("LOG_MESSAGE", errorMessages));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for new version
|
// check for new version in a separate thread
|
||||||
String releasedVersion = getReleasedVersion();
|
new Thread("CheckRelease") {
|
||||||
if (currentVersion != null && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) {
|
@Override
|
||||||
DavGatewayTray.info(new BundleMessage("LOG_NEW_VERSION_AVAILABLE", releasedVersion));
|
public void run() {
|
||||||
}
|
String releasedVersion = getReleasedVersion();
|
||||||
|
if (currentVersion != null && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) {
|
||||||
|
DavGatewayTray.info(new BundleMessage("LOG_NEW_VERSION_AVAILABLE", releasedVersion));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,11 +199,11 @@ public final class DavGateway {
|
||||||
HttpClient httpClient = DavGatewayHttpClientFacade.getInstance();
|
HttpClient httpClient = DavGatewayHttpClientFacade.getInstance();
|
||||||
GetMethod getMethod = new GetMethod(HTTP_DAVMAIL_SOURCEFORGE_NET_VERSION_TXT);
|
GetMethod getMethod = new GetMethod(HTTP_DAVMAIL_SOURCEFORGE_NET_VERSION_TXT);
|
||||||
try {
|
try {
|
||||||
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(1000);
|
|
||||||
int status = httpClient.executeMethod(getMethod);
|
int status = httpClient.executeMethod(getMethod);
|
||||||
if (status == HttpStatus.SC_OK) {
|
if (status == HttpStatus.SC_OK) {
|
||||||
versionReader = new BufferedReader(new InputStreamReader(getMethod.getResponseBodyAsStream()));
|
versionReader = new BufferedReader(new InputStreamReader(getMethod.getResponseBodyAsStream()));
|
||||||
version = versionReader.readLine();
|
version = versionReader.readLine();
|
||||||
|
LOGGER.debug("DavMail released version: "+version);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
DavGatewayTray.debug(new BundleMessage("LOG_UNABLE_TO_GET_RELEASED_VERSION"));
|
DavGatewayTray.debug(new BundleMessage("LOG_UNABLE_TO_GET_RELEASED_VERSION"));
|
||||||
|
|
|
@ -455,6 +455,7 @@ public final class DavGatewayHttpClientFacade {
|
||||||
if (multiThreadedHttpConnectionManager == null) {
|
if (multiThreadedHttpConnectionManager == null) {
|
||||||
multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
|
multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
|
||||||
multiThreadedHttpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(100);
|
multiThreadedHttpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(100);
|
||||||
|
multiThreadedHttpConnectionManager.getParams().setConnectionTimeout(10000);
|
||||||
httpConnectionManagerThread = new HttpConnectionManagerThread();
|
httpConnectionManagerThread = new HttpConnectionManagerThread();
|
||||||
httpConnectionManagerThread.start();
|
httpConnectionManagerThread.start();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue