use of org.apache.tomcat.util.net.DispatchType in project tomcat by apache.
the class AbstractProcessorLight method process.
@Override
public SocketState process(SocketWrapperBase<?> socketWrapper, SocketEvent status) throws IOException {
SocketState state = SocketState.CLOSED;
Iterator<DispatchType> dispatches = null;
do {
if (dispatches != null) {
DispatchType nextDispatch = dispatches.next();
state = dispatch(nextDispatch.getSocketStatus());
} else if (status == SocketEvent.DISCONNECT) {
// Do nothing here, just wait for it to get recycled
} else if (isAsync() || isUpgrade() || state == SocketState.ASYNC_END) {
state = dispatch(status);
if (state == SocketState.OPEN) {
// There may be pipe-lined data to read. If the data isn't
// processed now, execution will exit this loop and call
// release() which will recycle the processor (and input
// buffer) deleting any pipe-lined data. To avoid this,
// process it now.
state = service(socketWrapper);
}
} else if (status == SocketEvent.OPEN_WRITE) {
// Extra write event likely after async, ignore
state = SocketState.LONG;
} else {
state = service(socketWrapper);
}
if (state != SocketState.CLOSED && isAsync()) {
state = asyncPostProcess();
}
if (getLog().isDebugEnabled()) {
getLog().debug("Socket: [" + socketWrapper + "], Status in: [" + status + "], State out: [" + state + "]");
}
if (dispatches == null || !dispatches.hasNext()) {
// Only returns non-null iterator if there are
// dispatches to process.
dispatches = getIteratorAndClearDispatches();
}
} while (state == SocketState.ASYNC_END || dispatches != null && state != SocketState.CLOSED);
return state;
}
use of org.apache.tomcat.util.net.DispatchType in project tomcat by apache.
the class StreamProcessor method executeDispatches.
@Override
protected final void executeDispatches() {
Iterator<DispatchType> dispatches = getIteratorAndClearDispatches();
synchronized (this) {
/*
* TODO Check if this sync is necessary.
* Compare with superrclass that uses SocketWrapper
*/
while (dispatches != null && dispatches.hasNext()) {
DispatchType dispatchType = dispatches.next();
processSocketEvent(dispatchType.getSocketStatus(), false);
}
}
}
use of org.apache.tomcat.util.net.DispatchType in project tomcat by apache.
the class AbstractProcessor method executeDispatches.
protected void executeDispatches() {
SocketWrapperBase<?> socketWrapper = getSocketWrapper();
Iterator<DispatchType> dispatches = getIteratorAndClearDispatches();
if (socketWrapper != null) {
synchronized (socketWrapper) {
/*
* This method is called when non-blocking IO is initiated by defining
* a read and/or write listener in a non-container thread. It is called
* once the non-container thread completes so that the first calls to
* onWritePossible() and/or onDataAvailable() as appropriate are made by
* the container.
*
* Processing the dispatches requires (for APR/native at least)
* that the socket has been added to the waitingRequests queue. This may
* not have occurred by the time that the non-container thread completes
* triggering the call to this method. Therefore, the coded syncs on the
* SocketWrapper as the container thread that initiated this
* non-container thread holds a lock on the SocketWrapper. The container
* thread will add the socket to the waitingRequests queue before
* releasing the lock on the socketWrapper. Therefore, by obtaining the
* lock on socketWrapper before processing the dispatches, we can be
* sure that the socket has been added to the waitingRequests queue.
*/
while (dispatches != null && dispatches.hasNext()) {
DispatchType dispatchType = dispatches.next();
socketWrapper.processSocket(dispatchType.getSocketStatus(), false);
}
}
}
}
Aggregations