private Set<DispatchType> dispatches = new CopyOnWriteArraySet<>();
@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(); if (getLog().isDebugEnabled()) {
getLog().debug("Processing dispatch type: [" + nextDispatch + "]");
}
state = dispatch(nextDispatch.getSocketStatus()); if (!dispatches.hasNext()) {
state = checkForPipelinedData(state, socketWrapper);
}
} elseif (status == SocketEvent.DISCONNECT) { // Do nothing here, just wait for it to get recycled
} elseif (isAsync() || isUpgrade() || state == SocketState.ASYNC_END) {
state = dispatch(status);
state = checkForPipelinedData(state, socketWrapper);
} elseif (status == SocketEvent.OPEN_WRITE) { // Extra write event likely after async, ignore
state = SocketState.LONG;
} elseif (status == SocketEvent.OPEN_READ) {
state = service(socketWrapper);
} elseif (status == SocketEvent.CONNECT_FAIL) {
logAccess(socketWrapper);
} else { // Default to closing the socket if the SocketEvent passed in // is not consistent with the current state of the Processor
state = SocketState.CLOSED;
}
if (getLog().isDebugEnabled()) {
getLog().debug( "Socket: [" + socketWrapper + "], Status in: [" + status + "], State out: [" + state + "]");
}
if (isAsync()) {
state = asyncPostProcess(); if (getLog().isDebugEnabled()) {
getLog().debug( "Socket: [" + socketWrapper + "], State after async post processing: [" + 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;
}
private SocketState checkForPipelinedData(SocketState inState, SocketWrapperBase<?> socketWrapper) throws IOException { if (inState == 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. return service(socketWrapper);
} else { return inState;
}
}
public Iterator<DispatchType> getIteratorAndClearDispatches() { // Note: Logic in AbstractProtocol depends on this method only returning // a non-null value if the iterator is non-empty. i.e. it should never // return an empty iterator.
Iterator<DispatchType> result; synchronized (dispatches) { // Synchronized as the generation of the iterator and the clearing // of dispatches needs to be an atomic operation.
result = dispatches.iterator(); if (result.hasNext()) {
dispatches.clear();
} else {
result = null;
}
} return result;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.