Throwable cause) throws Exception {
if (cause instanceof WriteToClosedSessionException) {
// Filter out SSL close notify, which is likely to fail to flush
// due to disconnection.
WriteToClosedSessionException e = (WriteToClosedSessionException) cause;
List<WriteRequest> failedRequests = e.getRequests();
boolean containsCloseNotify = false;
for (WriteRequest r: failedRequests) {
if (isCloseNotify(r.getMessage())) {
containsCloseNotify = true;
break;
}
}
if (containsCloseNotify) {
if (failedRequests.size() == 1) {
// close notify is the only failed request; bail out.
return;
}
List<WriteRequest> newFailedRequests =
new ArrayList<WriteRequest>(failedRequests.size() - 1);
for (WriteRequest r: failedRequests) {
if (!isCloseNotify(r.getMessage())) {
newFailedRequests.add(r);
}
}
if (newFailedRequests.isEmpty()) {
// the failedRequests were full with close notify; bail out.
return;
}
cause = new WriteToClosedSessionException(
newFailedRequests, cause.getMessage(), cause.getCause());
}
}
nextFilter.exceptionCaught(session, cause);