Class AbstractIOReactor
- All Implemented Interfaces:
IOReactor
- Direct Known Subclasses:
BaseIOReactor
IOReactor that can used as a subclass
for more specialized I/O reactors. It is based on a single Selector
instance.- Since:
- 4.0
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractIOReactor(long selectTimeout) Creates new AbstractIOReactor instance.AbstractIOReactor(long selectTimeout, boolean interestOpsQueueing) Creates new AbstractIOReactor instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidacceptable(SelectionKey key) Triggered when the key signalsSelectionKey.OP_ACCEPTreadiness.voidaddChannel(ChannelEntry channelEntry) Adds new channel entry.voidawaitShutdown(long timeout) Blocks for the given period of time in milliseconds awaiting the completion of the reactor shutdown.protected voidCloses out all active channels registered with the selector of this I/O reactor.protected voidCloses out all new channels pending registration with the selector of this I/O reactor.protected voidCloses out all I/O sessions maintained by this I/O reactor.protected abstract voidconnectable(SelectionKey key) Triggered when the key signalsSelectionKey.OP_CONNECTreadiness.protected voidexecute()Activates the I/O reactor.booleanReturnstrueif interest Ops queueing is enabled,falseotherwise.protected IOSessiongetSession(SelectionKey key) ObtainsIOSessioninstance associated with the given selection key.Returns the current status of the reactor.voidAttempts graceful shutdown of this I/O reactor.voidAttempts force-shutdown of this I/O reactor.protected voidprocessEvent(SelectionKey key) Processes new event on the given selection key.protected voidqueueClosedSession(IOSession session) Queues the given I/O session to be processed asynchronously as closed.protected abstract voidreadable(SelectionKey key) Triggered when the key signalsSelectionKey.OP_READreadiness.protected voidsessionClosed(IOSession session) Triggered when a session has been closed.protected voidsessionCreated(SelectionKey key, IOSession session) Triggered when new session has been created.protected voidsessionTimedOut(IOSession session) Triggered when a session has timed out.voidshutdown()Initiates shutdown of the reactor and blocks for a default period of time waiting for the reactor to terminate all active connections, to shut down itself and to release system resources it currently holds.voidshutdown(long gracePeriod) Initiates shutdown of the reactor and blocks approximately for the given period of time in milliseconds waiting for the reactor to terminate all active connections, to shut down itself and to release system resources it currently holds.protected voidtimeoutCheck(SelectionKey key, long now) Triggered to verify whether the I/O session associated with the given selection key has not timed out.protected abstract voidvalidate(Set<SelectionKey> keys) Triggered to validate keys currently registered with the selector.protected abstract voidwritable(SelectionKey key) Triggered when the key signalsSelectionKey.OP_WRITEreadiness.
-
Constructor Details
-
AbstractIOReactor
Creates new AbstractIOReactor instance.- Parameters:
selectTimeout- the select timeout.- Throws:
IOReactorException- in case if a non-recoverable I/O error.
-
AbstractIOReactor
Creates new AbstractIOReactor 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
-
acceptable
Triggered when the key signalsSelectionKey.OP_ACCEPTreadiness.Super-classes can implement this method to react to the event.
- Parameters:
key- the selection key.
-
connectable
Triggered when the key signalsSelectionKey.OP_CONNECTreadiness.Super-classes can implement this method to react to the event.
- Parameters:
key- the selection key.
-
readable
Triggered when the key signalsSelectionKey.OP_READreadiness.Super-classes can implement this method to react to the event.
- Parameters:
key- the selection key.
-
writable
Triggered when the key signalsSelectionKey.OP_WRITEreadiness.Super-classes can implement this method to react to the event.
- Parameters:
key- the selection key.
-
validate
Triggered to validate keys currently registered with the selector. This method is called after each I/O select loop.Super-classes can implement this method to run validity checks on active sessions and include additional processing that needs to be executed after each I/O select loop.
- Parameters:
keys- all selection keys registered with the selector.
-
sessionCreated
Triggered when new session has been created.Super-classes can implement this method to react to the event.
- Parameters:
key- the selection key.session- new I/O session.
-
sessionClosed
Triggered when a session has been closed.Super-classes can implement this method to react to the event.
- Parameters:
session- closed I/O session.
-
sessionTimedOut
Triggered when a session has timed out.Super-classes can implement this method to react to the event.
- Parameters:
session- timed out I/O session.
-
getSession
ObtainsIOSessioninstance associated with the given selection key.- Parameters:
key- the selection key.- Returns:
- I/O session.
-
getStatus
Description copied from interface:IOReactorReturns the current status of the reactor. -
getInterestOpsQueueing
public boolean getInterestOpsQueueing()Returnstrueif interest Ops queueing is enabled,falseotherwise.- Since:
- 4.1
-
addChannel
Adds new channel entry. The channel will be asynchronously registered with the selector.- Parameters:
channelEntry- the channel entry.
-
execute
Activates the I/O reactor. The I/O reactor will start reacting to I/O events and triggering notification methods.This method will enter the infinite I/O select loop on the
Selectorinstance associated with this I/O reactor.The method will remain blocked unto the I/O reactor is shut down or the execution thread is interrupted.
- Throws:
InterruptedIOException- if the dispatch thread is interrupted.IOReactorException- in case if a non-recoverable I/O error.- See Also:
-
processEvent
Processes new event on the given selection key.- Parameters:
key- the selection key that triggered an event.
-
queueClosedSession
Queues the given I/O session to be processed asynchronously as closed.- Parameters:
session- the closed I/O session.
-
timeoutCheck
Triggered to verify whether the I/O session associated with the given selection key has not timed out.Super-classes can implement this method to react to the event.
- Parameters:
key- the selection key.now- current time as long value.
-
closeSessions
protected void closeSessions()Closes out all I/O sessions maintained by this I/O reactor. -
closeNewChannels
Closes out all new channels pending registration with the selector of this I/O reactor.- Throws:
IOReactorException- - not thrown currently
-
closeActiveChannels
Closes out all active channels registered with the selector of this I/O reactor.- Throws:
IOReactorException- - not thrown currently
-
gracefulShutdown
public void gracefulShutdown()Attempts graceful shutdown of this I/O reactor. -
hardShutdown
Attempts force-shutdown of this I/O reactor.- Throws:
IOReactorException
-
awaitShutdown
Blocks for the given period of time in milliseconds awaiting the completion of the reactor shutdown.- Parameters:
timeout- the maximum wait time.- Throws:
InterruptedException- if interrupted.
-
shutdown
Description copied from interface:IOReactorInitiates shutdown of the reactor and blocks approximately for the given period of time in milliseconds waiting for the reactor to terminate all active connections, to shut down itself and to release system resources it currently holds.- Specified by:
shutdownin interfaceIOReactor- Parameters:
gracePeriod- wait time in milliseconds.- Throws:
IOReactorException
-
shutdown
Description copied from interface:IOReactorInitiates shutdown of the reactor and blocks for a default period of time waiting for the reactor to terminate all active connections, to shut down itself and to release system resources it currently holds. It is up to individual implementations to decide for how long this method can remain blocked.- Specified by:
shutdownin interfaceIOReactor- Throws:
IOReactorException
-