org.apache.mina.transport.socket.apr

## Class AprIoProcessor

- java.lang.Object
- - org.apache.mina.core.polling.AbstractPollingIoProcessor<AprSession>
  - - org.apache.mina.transport.socket.apr.AprIoProcessor

- All Implemented Interfaces:
    IoProcessor<AprSession>

      public final class AprIoProcessor
      extends AbstractPollingIoProcessor<AprSession>

  The class in charge of processing socket level IO events for the `AprSocketConnector`
  Author:
    Apache MINA Project

- - ### Field Summary

    - ### Fields inherited from class org.apache.mina.core.polling.AbstractPollingIoProcessor

      `wakeupCalled`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AprIoProcessor(Executor executor)` Create a new instance of `AprIoProcessor` with a given Exector for handling I/Os events.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Iterator<AprSession>` | `allSessions()` Get an `Iterator` for the list of `IoSession` polled by this `IoProcessor`
    `protected void` | `destroy(AprSession session)` Destroy the underlying client socket handle
    `protected void` | `doDispose()` Dispose the resources used by this `IoProcessor` for polling the client connections.
    `protected SessionState` | `getState(AprSession session)` Get the state of a session (preparing, open, closed)
    `protected void` | `init(AprSession session)` Initialize the polling of a session.
    `protected boolean` | `isBrokenConnection()` Check that the select() has not exited immediately just because of a broken connection.
    `protected boolean` | `isInterestedInRead(AprSession session)` is this session registered for reading
    `protected boolean` | `isInterestedInWrite(AprSession session)` is this session registered for writing
    `protected boolean` | `isReadable(AprSession session)` Is the session ready for reading
    `protected boolean` | `isSelectorEmpty()` Say if the list of `IoSession` polled by this `IoProcessor` is empty
    `protected boolean` | `isWritable(AprSession session)` Is the session ready for writing
    `protected int` | `read(AprSession session, IoBuffer buffer)` Reads a sequence of bytes from a `IoSession` into the given `IoBuffer`.
    `protected void` | `registerNewSelector()` In the case we are using the java select() method, this method is used to trash the buggy selector and create a new one, registring all the sockets on it.
    `protected int` | `select()` poll those sessions forever
    `protected int` | `select(long timeout)` poll those sessions for the given timeout
    `protected Iterator<AprSession>` | `selectedSessions()` Get an `Iterator` for the list of `IoSession` found selected by the last call of {@link AbstractPollingIoProcessor#select(int)
    `protected void` | `setInterestedInRead(AprSession session, boolean isInterested)` register a session for reading
    `protected void` | `setInterestedInWrite(AprSession session, boolean isInterested)` register a session for writing
    `protected int` | `transferFile(AprSession session, FileRegion region, int length)` Write a part of a file to a `IoSession`, if the underlying API isn't supporting system calls like sendfile(), you can throw a `UnsupportedOperationException` so the file will be send using usual `AbstractPollingIoProcessor.write(AbstractIoSession, IoBuffer, int)` call.
    `protected void` | `wakeup()` Interrupt the {@link AbstractPollingIoProcessor#select(int) call.
    `protected int` | `write(AprSession session, IoBuffer buf, int length)` Write a sequence of bytes to a `IoSession`, means to be called when a session was found ready for writing.

    - ### Methods inherited from class org.apache.mina.core.polling.AbstractPollingIoProcessor

      `add, dispose, flush, isDisposed, isDisposing, remove, updateTrafficControl, updateTrafficMask, write`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AprIoProcessor

          public AprIoProcessor(Executor executor)

      Create a new instance of `AprIoProcessor` with a given Exector for handling I/Os events.
      Parameters:
        `executor` - the `Executor` for handling I/O events

  - ### Method Detail

    - #### doDispose

          protected void doDispose()

      Dispose the resources used by this `IoProcessor` for polling the client connections. The implementing class doDispose method will be called.
      Specified by:
        `doDispose` in class `AbstractPollingIoProcessor<AprSession>`

    - #### select

          protected int select()
                        throws Exception

      poll those sessions forever
      Specified by:
        `select` in class `AbstractPollingIoProcessor<AprSession>`
      Returns:
        The number of session ready for read or for write
      Throws:
        `Exception` - if some low level IO error occurs

    - #### select

          protected int select(long timeout)
                        throws Exception

      poll those sessions for the given timeout
      Specified by:
        `select` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `timeout` - milliseconds before the call timeout if no event appear
      Returns:
        The number of session ready for read or for write
      Throws:
        `Exception` - if some low level IO error occurs

    - #### isSelectorEmpty

          protected boolean isSelectorEmpty()

      Say if the list of `IoSession` polled by this `IoProcessor` is empty
      Specified by:
        `isSelectorEmpty` in class `AbstractPollingIoProcessor<AprSession>`
      Returns:
        true if at least a session is managed by this `IoProcessor`

    - #### wakeup

          protected void wakeup()

      Interrupt the {@link AbstractPollingIoProcessor#select(int) call.
      Specified by:
        `wakeup` in class `AbstractPollingIoProcessor<AprSession>`

    - #### allSessions

          protected Iterator<AprSession> allSessions()

      Get an `Iterator` for the list of `IoSession` polled by this `IoProcessor`
      Specified by:
        `allSessions` in class `AbstractPollingIoProcessor<AprSession>`
      Returns:
        `Iterator` of `IoSession`

    - #### selectedSessions

          protected Iterator<AprSession> selectedSessions()

      Get an `Iterator` for the list of `IoSession` found selected by the last call of {@link AbstractPollingIoProcessor#select(int)
      Specified by:
        `selectedSessions` in class `AbstractPollingIoProcessor<AprSession>`
      Returns:
        `Iterator` of `IoSession` read for I/Os operation

    - #### init

          protected void init(AprSession session)
                       throws Exception

      Description copied from class: `AbstractPollingIoProcessor`
      Initialize the polling of a session. Add it to the polling process.
      Specified by:
        `init` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the `IoSession` to add to the polling
      Throws:
        `Exception` - any exception thrown by the underlying system calls

    - #### destroy

          protected void destroy(AprSession session)
                          throws Exception

      Destroy the underlying client socket handle
      Specified by:
        `destroy` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the `IoSession`
      Throws:
        `Exception` - any exception thrown by the underlying system calls

    - #### getState

          protected SessionState getState(AprSession session)

      Get the state of a session (preparing, open, closed)
      Specified by:
        `getState` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the `IoSession` to inspect
      Returns:
        the state of the session

    - #### isReadable

          protected boolean isReadable(AprSession session)

      Is the session ready for reading
      Specified by:
        `isReadable` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session queried
      Returns:
        true is ready, false if not ready

    - #### isWritable

          protected boolean isWritable(AprSession session)

      Is the session ready for writing
      Specified by:
        `isWritable` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session queried
      Returns:
        true is ready, false if not ready

    - #### isInterestedInRead

          protected boolean isInterestedInRead(AprSession session)

      is this session registered for reading
      Specified by:
        `isInterestedInRead` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session queried
      Returns:
        true is registered for reading

    - #### isInterestedInWrite

          protected boolean isInterestedInWrite(AprSession session)

      is this session registered for writing
      Specified by:
        `isInterestedInWrite` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session queried
      Returns:
        true is registered for writing

    - #### setInterestedInRead

          protected void setInterestedInRead(AprSession session,
                                 boolean isInterested)
                                      throws Exception

      register a session for reading
      Specified by:
        `setInterestedInRead` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session registered
        `isInterested` - true for registering, false for removing
      Throws:
        `Exception`

    - #### setInterestedInWrite

          protected void setInterestedInWrite(AprSession session,
                                  boolean isInterested)
                                       throws Exception

      register a session for writing
      Specified by:
        `setInterestedInWrite` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session registered
        `isInterested` - true for registering, false for removing
      Throws:
        `Exception`

    - #### read

          protected int read(AprSession session,
                 IoBuffer buffer)
                      throws Exception

      Reads a sequence of bytes from a `IoSession` into the given `IoBuffer`. Is called when the session was found ready for reading.
      Specified by:
        `read` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session to read
        `buffer` - the buffer to fill
      Returns:
        the number of bytes read
      Throws:
        `Exception` - any exception thrown by the underlying system calls

    - #### write

          protected int write(AprSession session,
                  IoBuffer buf,
                  int length)
                       throws Exception

      Write a sequence of bytes to a `IoSession`, means to be called when a session was found ready for writing.
      Specified by:
        `write` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session to write
        `buf` - the buffer to write
        `length` - the number of bytes to write can be superior to the number of bytes remaining in the buffer
      Returns:
        the number of byte written
      Throws:
        `Exception` - any exception thrown by the underlying system calls

    - #### transferFile

          protected int transferFile(AprSession session,
                         FileRegion region,
                         int length)
                              throws Exception

      Write a part of a file to a `IoSession`, if the underlying API isn't supporting system calls like sendfile(), you can throw a `UnsupportedOperationException` so the file will be send using usual `AbstractPollingIoProcessor.write(AbstractIoSession, IoBuffer, int)` call.
      Specified by:
        `transferFile` in class `AbstractPollingIoProcessor<AprSession>`
      Parameters:
        `session` - the session to write
        `region` - the file region to write
        `length` - the length of the portion to send
      Returns:
        the number of written bytes
      Throws:
        `Exception` - any exception thrown by the underlying system calls

    - #### registerNewSelector

          protected void registerNewSelector()

      In the case we are using the java select() method, this method is used to trash the buggy selector and create a new one, registring all the sockets on it.
      Specified by:
        `registerNewSelector` in class `AbstractPollingIoProcessor<AprSession>`

    - #### isBrokenConnection

          protected boolean isBrokenConnection()
                                        throws IOException

      Check that the select() has not exited immediately just because of a broken connection. In this case, this is a standard case, and we just have to loop.
      Specified by:
        `isBrokenConnection` in class `AbstractPollingIoProcessor<AprSession>`
      Returns:
        true if a connection has been brutally closed.
      Throws:
        `IOException` - If we got an exception

Copyright © 2004-2012 Apache MINA Project. All Rights Reserved.