Class BaseIOReactor

  • All Implemented Interfaces:
    IOReactor

    public class BaseIOReactor
    extends AbstractIOReactor
    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
    • Field Detail

      • timeoutCheckInterval

        private final long timeoutCheckInterval
      • bufferingSessions

        private final java.util.Set<IOSession> bufferingSessions
      • lastTimeoutCheck

        private long lastTimeoutCheck
    • 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 given IOEventDispatch.
        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 given RuntimeException. This method delegates handling of the exception to the IOReactorExceptionHandler, 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 the SelectionKey.OP_ACCEPT event.

        Super-classes can override this method to react to the event.

        Specified by:
        acceptable in class AbstractIOReactor
        Parameters:
        key - the selection key.
      • connectable

        protected void connectable​(java.nio.channels.SelectionKey key)
        This I/O reactor implementation does not react to the SelectionKey.OP_CONNECT event.

        Super-classes can override this method to react to the event.

        Specified by:
        connectable in class AbstractIOReactor
        Parameters:
        key - the selection key.
      • readable

        protected void readable​(java.nio.channels.SelectionKey key)
        Processes SelectionKey.OP_READ event on the given selection key. This method dispatches the event notification to the IOEventDispatch.inputReady(IOSession) method.
        Specified by:
        readable in class AbstractIOReactor
        Parameters:
        key - the selection key.
      • writable

        protected void writable​(java.nio.channels.SelectionKey key)
        Processes SelectionKey.OP_WRITE event on the given selection key. This method dispatches the event notification to the IOEventDispatch.outputReady(IOSession) method.
        Specified by:
        writable in class AbstractIOReactor
        Parameters:
        key - the selection key.