Skip to content

Commit

Permalink
Cleaner implementation of server detecting client disconnection in sa…
Browse files Browse the repository at this point in the history
…mpling stream
  • Loading branch information
mattrjacobs committed Dec 14, 2016
1 parent 11ca011 commit bf6922a
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,12 @@ public void onError(Throwable e) {
@Override
public void onNext(String sampleDataAsString) {
if (sampleDataAsString != null) {
try {
writer.print("data: " + sampleDataAsString + "\n\n");
// explicitly check for client disconnect - PrintWriter does not throw exceptions
if (writer.checkError()) {
throw new IOException("io error");
}
writer.flush();
} catch (IOException ioe) {
writer.print("data: " + sampleDataAsString + "\n\n");
// explicitly check for client disconnect - PrintWriter does not throw exceptions
if (writer.checkError()) {
moreDataWillBeSent.set(false);
}
writer.flush();
}
}
});
Expand All @@ -167,17 +163,16 @@ public void onNext(String sampleDataAsString) {
writer.print("ping: \n\n");
// explicitly check for client disconnect - PrintWriter does not throw exceptions
if (writer.checkError()) {
throw new IOException("io error");
moreDataWillBeSent.set(false);
}
writer.flush();
} catch (InterruptedException e) {
moreDataWillBeSent.set(false);
} catch (IOException ioe) {
moreDataWillBeSent.set(false);
}
}
}
} finally {
System.out.println("Exiting the server thread, current count = " + getNumberCurrentConnections());
decrementCurrentConcurrentConnections();
if (sampleSubscription != null && !sampleSubscription.isUnsubscribed()) {
sampleSubscription.unsubscribe();
Expand Down

0 comments on commit bf6922a

Please sign in to comment.