public void exchangeComplete(final HttpServerExchange exchange) {
connection.clearChannel();
final HttpServerConnection connection = this.connection;
if (exchange.isPersistent() && !exchange.isUpgrade()) {
final StreamConnection channel = connection.getChannel();
if (connection.getExtraBytes() == null) {
//if we are not pipelining we just register a listener
//we have to resume from with the io thread
while (requestStateUpdater.get(this) != 0) {
if (requestStateUpdater.compareAndSet(this, 1, 2)) {
newRequest();
channel.getSourceChannel().setReadListener(HttpReadListener.this);
channel.getSourceChannel().resumeReads();
requestStateUpdater.set(this, 0);
}
}
} else {
requestStateUpdater.set(this, 0); //no need to CAS, as we don't actually resume
newRequest();
if (exchange.isInIoThread()) {
//no need to suspend reads here, the task will always run before the read listener anyway
channel.getIoThread().execute(this);
} else {
channel.getSourceChannel().suspendReads();
Executor executor = exchange.getDispatchExecutor();
if (executor == null) {
executor = exchange.getConnection().getWorker();
}
executor.execute(this);