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
public class BaseIOReactor extends AbstractIOReactor
Default implementation ofAbstractIOReactor
that serves as a base for more advancedIOReactor
implementations. This class adds support for the I/O event dispatching usingIOEventDispatch
, management of buffering sessions, and session timeout handling.- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<IOSession>
bufferingSessions
private IOEventDispatch
eventDispatch
private IOReactorExceptionHandler
exceptionHandler
private long
lastTimeoutCheck
private long
timeoutCheckInterval
-
Constructor Summary
Constructors Constructor Description BaseIOReactor(long selectTimeout)
Creates new BaseIOReactor instance.BaseIOReactor(long selectTimeout, boolean interestOpsQueueing)
Creates new BaseIOReactor instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
acceptable(java.nio.channels.SelectionKey key)
This I/O reactor implementation does not react to theSelectionKey.OP_ACCEPT
event.protected void
connectable(java.nio.channels.SelectionKey key)
This I/O reactor implementation does not react to theSelectionKey.OP_CONNECT
event.void
execute(IOEventDispatch eventDispatch)
Activates the I/O reactor.protected void
handleRuntimeException(java.lang.RuntimeException ex)
Handles the givenRuntimeException
.protected void
readable(java.nio.channels.SelectionKey key)
ProcessesSelectionKey.OP_READ
event on the given selection key.protected void
sessionClosed(IOSession session)
Processes closed I/O session.protected void
sessionCreated(java.nio.channels.SelectionKey key, IOSession session)
Processes newly created I/O session.protected void
sessionTimedOut(IOSession session)
Processes timed out I/O session.void
setExceptionHandler(IOReactorExceptionHandler exceptionHandler)
Sets exception handler for this I/O reactor.protected void
validate(java.util.Set<java.nio.channels.SelectionKey> keys)
Verifies whether any of the sessions associated with the given selection keys timed out by invoking theAbstractIOReactor.timeoutCheck(SelectionKey, long)
method.protected void
writable(java.nio.channels.SelectionKey key)
ProcessesSelectionKey.OP_WRITE
event 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
-
-
-
-
Field Detail
-
timeoutCheckInterval
private final long timeoutCheckInterval
-
bufferingSessions
private final java.util.Set<IOSession> bufferingSessions
-
lastTimeoutCheck
private long lastTimeoutCheck
-
exceptionHandler
private IOReactorExceptionHandler exceptionHandler
-
eventDispatch
private IOEventDispatch eventDispatch
-
-
Constructor Detail
-
BaseIOReactor
public BaseIOReactor(long selectTimeout) throws IOReactorException
Creates new BaseIOReactor instance.- Parameters:
selectTimeout
- the select timeout.- Throws:
IOReactorException
- in case if a non-recoverable I/O error.
-
BaseIOReactor
public BaseIOReactor(long selectTimeout, boolean interestOpsQueueing) throws IOReactorException
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 Detail
-
execute
public void execute(IOEventDispatch eventDispatch) throws java.io.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:
java.io.InterruptedIOException
- if the dispatch thread is interrupted.IOReactorException
- in case if a non-recoverable I/O error.
-
setExceptionHandler
public void setExceptionHandler(IOReactorExceptionHandler exceptionHandler)
Sets exception handler for this I/O reactor.- Parameters:
exceptionHandler
- the exception handler.
-
handleRuntimeException
protected void handleRuntimeException(java.lang.RuntimeException ex)
Handles the givenRuntimeException
. This method delegates handling of the exception to theIOReactorExceptionHandler
, if available.- Parameters:
ex
- the runtime exception.
-
acceptable
protected void acceptable(java.nio.channels.SelectionKey key)
This I/O reactor implementation does not react to theSelectionKey.OP_ACCEPT
event.Super-classes can override this method to react to the event.
- Specified by:
acceptable
in classAbstractIOReactor
- Parameters:
key
- the selection key.
-
connectable
protected void connectable(java.nio.channels.SelectionKey key)
This I/O reactor implementation does not react to theSelectionKey.OP_CONNECT
event.Super-classes can override this method to react to the event.
- Specified by:
connectable
in classAbstractIOReactor
- Parameters:
key
- the selection key.
-
readable
protected void readable(java.nio.channels.SelectionKey key)
ProcessesSelectionKey.OP_READ
event on the given selection key. This method dispatches the event notification to theIOEventDispatch.inputReady(IOSession)
method.- Specified by:
readable
in classAbstractIOReactor
- Parameters:
key
- the selection key.
-
writable
protected void writable(java.nio.channels.SelectionKey key)
ProcessesSelectionKey.OP_WRITE
event on the given selection key. This method dispatches the event notification to theIOEventDispatch.outputReady(IOSession)
method.- Specified by:
writable
in classAbstractIOReactor
- Parameters:
key
- the selection key.
-
validate
protected void validate(java.util.Set<java.nio.channels.SelectionKey> keys)
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:
validate
in classAbstractIOReactor
- Parameters:
keys
- all selection keys registered with the selector.
-
sessionCreated
protected void sessionCreated(java.nio.channels.SelectionKey key, IOSession session)
Processes newly created I/O session. This method dispatches the event notification to theIOEventDispatch.connected(IOSession)
method.- Overrides:
sessionCreated
in classAbstractIOReactor
- Parameters:
key
- the selection key.session
- new I/O session.
-
sessionTimedOut
protected void sessionTimedOut(IOSession session)
Processes timed out I/O session. This method dispatches the event notification to theIOEventDispatch.timeout(IOSession)
method.- Overrides:
sessionTimedOut
in classAbstractIOReactor
- Parameters:
session
- timed out I/O session.
-
sessionClosed
protected void sessionClosed(IOSession session)
Processes closed I/O session. This method dispatches the event notification to theIOEventDispatch.disconnected(IOSession)
method.- Overrides:
sessionClosed
in classAbstractIOReactor
- Parameters:
session
- closed I/O session.
-
-