Skip to content

Commit

Permalink
Merge pull request #530 from jboyd01/master
Browse files Browse the repository at this point in the history
Add shutdown hook for WebSphere and checkError() to detect disconnected client
  • Loading branch information
mattrjacobs committed Jan 20, 2015
2 parents f0c4c90 + 223b1ea commit 85e058c
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,21 @@ public class HystrixMetricsStreamServlet extends HttpServlet {
private static AtomicInteger concurrentConnections = new AtomicInteger(0);
private static DynamicIntProperty maxConcurrentConnections = DynamicPropertyFactory.getInstance().getIntProperty("hystrix.stream.maxConcurrentConnections", 5);

private volatile boolean isDestroyed = false;
private static volatile boolean isDestroyed = false;

/**
* WebSphere won't shutdown a servlet until after a 60 second timeout if there is an instance of the servlet executing
* a request. Add this method to enable a hook to notify Hystrix to shutdown. You must invoke this method at
* shutdown, perhaps from some other serverlet's destroy() method.
*/
public static void shutdown() {
isDestroyed = true;
}

@Override
public void init() throws ServletException {
isDestroyed = false;
}

/**
* Handle incoming GETs
Expand Down Expand Up @@ -146,6 +160,11 @@ private void handleRequest(HttpServletRequest request, HttpServletResponse respo
// after outputting all the messages we will flush the stream
response.flushBuffer();

// explicitly check for client disconnect - PrintWriter does not throw exceptions
if (response.getWriter().checkError()) {
throw new IOException("io error");
}

// now wait the 'delay' time
Thread.sleep(delay);
}
Expand Down

0 comments on commit 85e058c

Please sign in to comment.