final TaskQueue<AsyncReadQueueRecord> connectionQueue =
nioConnection.getAsyncReadQueue();
boolean done = false;
AsyncReadQueueRecord queueRecord = null;
try {
while ((queueRecord =
connectionQueue.obtainCurrentElementAndReserve()) != null) {
final ReadResult currentResult = queueRecord.getCurrentResult();
doRead(nioConnection, queueRecord);
final Interceptor<ReadResult> interceptor =
queueRecord.getInterceptor();
// check if message was completely read
final int interceptInstructions = intercept(
Reader.READ_EVENT, queueRecord,
currentResult);
if ((interceptInstructions & Interceptor.COMPLETED) != 0
|| (interceptor == null && queueRecord.isFinished())) {
// Is here a chance that queue becomes empty?
// If yes - we need to switch to manual io event processing
// mode to *disable READ interest for SameThreadStrategy*,
// so we don't get stuck, when other thread tried to add data
// to the queue.
if (!context.isManualIOEventControl() &&
connectionQueue.spaceInBytes() - 1 <= 0) {
context.setManualIOEventControl();
}
done = (connectionQueue.releaseSpaceAndNotify(1) == 0);
queueRecord.notifyComplete();
intercept(Reader.COMPLETE_EVENT, queueRecord, null);
queueRecord.recycle();
// check if there is ready element in the queue
if (done) {
break;
}
} else { // if there is still some data in current message
if ((interceptInstructions & Interceptor.RESET) != 0) {
currentResult.setMessage(null);
currentResult.setReadSize(0);
queueRecord.setMessage(null);
}
connectionQueue.setCurrentElement(queueRecord);
queueRecord.notifyIncomplete();
intercept(Reader.INCOMPLETE_EVENT, queueRecord, null);
// onReadyToRead(nioConnection);
return AsyncResult.INCOMPLETE;
}