try {
readIntoBufferNonBlocking();
if (pooled != null) {
state |= FLAG_READY;
if (!anyAreSet(state, FLAG_FINISHED)) {
CompositeThreadSetupAction action = request.getServletContext().getDeployment().getThreadSetupAction();
ThreadSetupAction.Handle handle = action.setup(request.getExchange());
try {
listener.onDataAvailable();
} finally {
handle.tearDown();
}
if(pooled != null) {
//they did not consume all the data
channel.suspendReads();
}
}
}
} catch (Exception e) {
CompositeThreadSetupAction action = request.getServletContext().getDeployment().getThreadSetupAction();
ThreadSetupAction.Handle handle = action.setup(request.getExchange());
try {
listener.onError(e);
} finally {
handle.tearDown();
}
IoUtils.safeClose(channel);
}
if (anyAreSet(state, FLAG_FINISHED)) {
if (anyAreClear(state, FLAG_ON_DATA_READ_CALLED)) {
try {
state |= FLAG_ON_DATA_READ_CALLED;
channel.shutdownReads();
CompositeThreadSetupAction action = request.getServletContext().getDeployment().getThreadSetupAction();
ThreadSetupAction.Handle handle = action.setup(request.getExchange());
try {
listener.onAllDataRead();
} finally {
handle.tearDown();
}