summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2019-02-08 15:32:09 +0100
committerSimon Rettberg2019-02-08 15:32:09 +0100
commit95dce7bab2cc9738b7e4185302f3fe1a44fbc8dd (patch)
tree31d28723b03dbc7ff2ef13ffcfeda3c359902772 /src
parenttable.html: Fix bytes/s for counter; design tweaks (diff)
downloaddnbd3-status-95dce7bab2cc9738b7e4185302f3fe1a44fbc8dd.tar.gz
dnbd3-status-95dce7bab2cc9738b7e4185302f3fe1a44fbc8dd.tar.xz
dnbd3-status-95dce7bab2cc9738b7e4185302f3fe1a44fbc8dd.zip
Increase polling timeout; fix error handling
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java b/src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java
index 97b5f5a..492e371 100644
--- a/src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java
+++ b/src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java
@@ -33,13 +33,13 @@ public class ServerPoller
public Status update()
{
HttpURLConnection con = null;
- InputStream is;
+ InputStream is = null;
try {
con = (HttpURLConnection)new URL( this.server ).openConnection();
con.setRequestMethod( "GET" );
- con.setConnectTimeout( 1000 );
- con.setReadTimeout( 2000 );
+ con.setConnectTimeout( 2000 );
+ con.setReadTimeout( 4000 );
if ( con.getResponseCode() != HttpURLConnection.HTTP_OK ) {
return null;
@@ -47,8 +47,12 @@ public class ServerPoller
is = con.getInputStream();
} catch ( java.net.SocketTimeoutException e ) {
+ System.out.println( "Timeout " + this.server );
+ NanoHTTPD.safeClose( is );
return null;
} catch ( java.io.IOException e ) {
+ System.out.println( "IOException " + this.server );
+ NanoHTTPD.safeClose( is );
return null;
}
// Now read data
@@ -61,10 +65,17 @@ public class ServerPoller
}
NanoHTTPD.safeClose( isr );
NanoHTTPD.safeClose( is );
- NanoHTTPD.safeClose( con.getErrorStream() );
status.setAddress( address );
status.setTimestamp( System.currentTimeMillis() );
} catch ( Exception e ) {
+ try {
+ InputStream es = con.getErrorStream();
+ while ( es.read( buffer ) > 0 ) {
+ // Nothingness
+ }
+ NanoHTTPD.safeClose( es );
+ } catch ( Exception e2 ) {
+ }
e.printStackTrace();
status = null;
}