Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,7 @@ private void assureReadyAndDrainedTurnsFalse() {
private void runOrBuffer(ActionItem actionItem) throws IOException {
WriteState curState = writeState.get();
if (curState.readyAndDrained) { // write to the outputStream directly
try {
actionItem.run();
} catch (IllegalStateException e) {
if (actionItem == flushAction || actionItem == completeAction) {
throw e;
}
buffer(actionItem, curState);
return;
}
actionItem.run();
if (actionItem == completeAction) {
return;
}
Expand All @@ -238,26 +230,20 @@ private void runOrBuffer(ActionItem actionItem) throws IOException {
log.finest("the servlet output stream becomes not ready");
}
} else { // buffer to the writeChain
buffer(actionItem, curState);
writeChain.offer(actionItem);
if (!writeState.compareAndSet(curState, curState.withReadyAndDrained(false))) {
checkState(
writeState.get().readyAndDrained,
"Bug: onWritePossible() should have changed readyAndDrained to true, but not");
ActionItem lastItem = writeChain.poll();
if (lastItem != null) {
checkState(lastItem == actionItem, "Bug: lastItem != actionItem");
runOrBuffer(lastItem);
}
} // state has not changed since
}
}

private void buffer(ActionItem actionItem, WriteState curState) throws IOException {
writeChain.offer(actionItem);
if (writeState.compareAndSet(curState, curState.withReadyAndDrained(false))) {
LockSupport.unpark(parkingThread);
} else {
checkState(
writeState.get().readyAndDrained,
"Bug: onWritePossible() should have changed readyAndDrained to true, but not");
ActionItem lastItem = writeChain.poll();
if (lastItem != null) {
checkState(lastItem == actionItem, "Bug: lastItem != actionItem");
runOrBuffer(lastItem);
}
} // state has not changed since
}

/** Write actions, e.g. writeBytes, flush, complete. */
@FunctionalInterface
@VisibleForTesting
Expand Down

This file was deleted.