Package org.apache.http.impl.nio.reactor
Class BaseIOReactor
java.lang.Object
org.apache.http.impl.nio.reactor.AbstractIOReactor
org.apache.http.impl.nio.reactor.BaseIOReactor
- All Implemented Interfaces:
IOReactor
Default implementation of
AbstractIOReactor that serves as a base
for more advanced IOReactor
implementations. This class adds support for the I/O event dispatching
using IOEventDispatch, management of buffering sessions, and
session timeout handling.- Since:
- 4.0
-
Constructor Summary
ConstructorsConstructorDescriptionBaseIOReactor(long selectTimeout) Creates new BaseIOReactor instance.BaseIOReactor(long selectTimeout, boolean interestOpsQueueing) Creates new BaseIOReactor instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidacceptable(SelectionKey key) This I/O reactor implementation does not react to theSelectionKey.OP_ACCEPTevent.protected voidconnectable(SelectionKey key) This I/O reactor implementation does not react to theSelectionKey.OP_CONNECTevent.voidexecute(IOEventDispatch eventDispatch) Activates the I/O reactor.protected voidHandles the givenRuntimeException.protected voidreadable(SelectionKey key) ProcessesSelectionKey.OP_READevent on the given selection key.protected voidsessionClosed(IOSession session) Processes closed I/O session.protected voidsessionCreated(SelectionKey key, IOSession session) Processes newly created I/O session.protected voidsessionTimedOut(IOSession session) Processes timed out I/O session.voidsetExceptionHandler(IOReactorExceptionHandler exceptionHandler) Sets exception handler for this I/O reactor.protected voidvalidate(Set<SelectionKey> keys) Verifies whether any of the sessions associated with the given selection keys timed out by invoking theAbstractIOReactor.timeoutCheck(SelectionKey, long)method.protected voidwritable(SelectionKey key) ProcessesSelectionKey.OP_WRITEevent on the given selection key.Methods inherited from class org.apache.http.impl.nio.reactor.AbstractIOReactor
addChannel, awaitShutdown, closeActiveChannels, closeNewChannels, closeSessions, execute, getInterestOpsQueueing, getSession, getStatus, gracefulShutdown, hardShutdown, processEvent, queueClosedSession, shutdown, shutdown, timeoutCheck
-
Constructor Details
-
BaseIOReactor
Creates new BaseIOReactor instance.- Parameters:
selectTimeout- the select timeout.- Throws:
IOReactorException- in case if a non-recoverable I/O error.
-
BaseIOReactor
Creates new BaseIOReactor instance.- Parameters:
selectTimeout- the select timeout.interestOpsQueueing- Ops queueing flag.- Throws:
IOReactorException- in case if a non-recoverable I/O error.- Since:
- 4.1
-
-
Method Details
-
execute
public void execute(IOEventDispatch eventDispatch) throws InterruptedIOException, IOReactorException Activates the I/O reactor. The I/O reactor will start reacting to I/O events and dispatch I/O event notifications to the givenIOEventDispatch.- Parameters:
eventDispatch- the I/O event dispatch.- Throws:
InterruptedIOException- if the dispatch thread is interrupted.IOReactorException- in case if a non-recoverable I/O error.
-
setExceptionHandler
Sets exception handler for this I/O reactor.- Parameters:
exceptionHandler- the exception handler.
-
handleRuntimeException
Handles the givenRuntimeException. This method delegates handling of the exception to theIOReactorExceptionHandler, if available.- Parameters:
ex- the runtime exception.
-
acceptable
This I/O reactor implementation does not react to theSelectionKey.OP_ACCEPTevent.Super-classes can override this method to react to the event.
- Specified by:
acceptablein classAbstractIOReactor- Parameters:
key- the selection key.
-
connectable
This I/O reactor implementation does not react to theSelectionKey.OP_CONNECTevent.Super-classes can override this method to react to the event.
- Specified by:
connectablein classAbstractIOReactor- Parameters:
key- the selection key.
-
readable
ProcessesSelectionKey.OP_READevent on the given selection key. This method dispatches the event notification to theIOEventDispatch.inputReady(IOSession)method.- Specified by:
readablein classAbstractIOReactor- Parameters:
key- the selection key.
-
writable
ProcessesSelectionKey.OP_WRITEevent on the given selection key. This method dispatches the event notification to theIOEventDispatch.outputReady(IOSession)method.- Specified by:
writablein classAbstractIOReactor- Parameters:
key- the selection key.
-
validate
Verifies whether any of the sessions associated with the given selection keys timed out by invoking theAbstractIOReactor.timeoutCheck(SelectionKey, long)method.This method will also invoke the
IOEventDispatch.inputReady(IOSession)method on all sessions that have buffered input data.- Specified by:
validatein classAbstractIOReactor- Parameters:
keys- all selection keys registered with the selector.
-
sessionCreated
Processes newly created I/O session. This method dispatches the event notification to theIOEventDispatch.connected(IOSession)method.- Overrides:
sessionCreatedin classAbstractIOReactor- Parameters:
key- the selection key.session- new I/O session.
-
sessionTimedOut
Processes timed out I/O session. This method dispatches the event notification to theIOEventDispatch.timeout(IOSession)method.- Overrides:
sessionTimedOutin classAbstractIOReactor- Parameters:
session- timed out I/O session.
-
sessionClosed
Processes closed I/O session. This method dispatches the event notification to theIOEventDispatch.disconnected(IOSession)method.- Overrides:
sessionClosedin classAbstractIOReactor- Parameters:
session- closed I/O session.
-