Permalink
Browse files

Linked aggressive re-connect to the autoconnect flag

  • Loading branch information...
1 parent 7f36466 commit 39a088626358da86d6bfdcb1feb61bfbbfb70108 @theterg theterg committed Jul 11, 2012
View
7 ...labs.bug.swarm.client/src/com/buglabs/bug/swarm/client/impl/SwarmParticipationReader.java
@@ -44,6 +44,7 @@
private final List<ISwarmMessageListener> listeners;
private final static ObjectMapper mapper = new ObjectMapper();
private final Socket socket;
+ private final boolean autoreconnect;
private long last_message;
/**
@@ -52,12 +53,14 @@
* @param listeners List of ISwarmMessageListener. Must not be null.
* @throws UnsupportedEncodingException
*/
- protected SwarmParticipationReader(Socket sock, String apiKey, List<ISwarmMessageListener> listeners) throws UnsupportedEncodingException, IOException{
+ protected SwarmParticipationReader(Socket sock, String apiKey, List<ISwarmMessageListener> listeners,
+ boolean autoreconnect) throws UnsupportedEncodingException, IOException{
AbstractSwarmWSClient.validateParams(sock, apiKey, listeners);
InputStream is = sock.getInputStream();
this.socket = sock;
this.apiKey = apiKey;
this.listeners = listeners;
+ this.autoreconnect = autoreconnect;
this.reader = new BufferedReader(new InputStreamReader(is, ISwarmClient.SWARM_CHARACTER_ENCODING));
}
@@ -75,7 +78,7 @@ public void run() {
try {
line = reader.readLine();
} catch (SocketTimeoutException e) {
- if (last_message + SwarmSessionImp.MAX_INTERVAL + 100 < new Date().getTime()){
+ if (autoreconnect && (last_message + SwarmSessionImp.MAX_INTERVAL + 100 < new Date().getTime())){
System.out.println("["+this.getClass().getSimpleName()+"]: "+"Connection stale, forcing the socket closed to trigger reconnect");
socket.close();
}
View
2 com.buglabs.bug.swarm.client/src/com/buglabs/bug/swarm/client/impl/SwarmSessionImp.java
@@ -109,7 +109,7 @@ private Socket createSocket(String hostname, int port) throws UnknownHostExcepti
if (readerThread != null)
readerThread.interrupt();
- this.readerThread = new SwarmParticipationReader(socket, apiKey, listeners);
+ this.readerThread = new SwarmParticipationReader(socket, apiKey, listeners, autoreconnect);
this.readerThread.start();
//sendHeader();

0 comments on commit 39a0886

Please sign in to comment.