org.apache.mina.transport.nio

## Class AbstractNioSession

- java.lang.Object
- - org.apache.mina.session.AbstractIoSession
  - - org.apache.mina.transport.nio.AbstractNioSession

- All Implemented Interfaces:
    IoSession, ReadFilterChainController, WriteFilterChainController
  Direct Known Subclasses:
    NioTcpSession, NioUdpSession

      public abstract class AbstractNioSession
      extends AbstractIoSession

  Common ancestor for NIO based `IoSession` implmentation.
  Author:
    Apache MINA Project

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.apache.mina.api.IoSession

      `IoSession.SessionState`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected SelectableChannel` | `channel` the NIO channel for this session

    - ### Fields inherited from class org.apache.mina.session.AbstractIoSession

      `config, idleChecker, secured, state`

    - ### Fields inherited from interface org.apache.mina.api.IoSession

      `SSL_HELPER`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractNioSession(IoService service, SelectableChannel channel, IdleChecker idleChecker)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `channelClose()` Close the inner socket channel
    `IoFuture<Void>` | `close(boolean immediately)` Closes this session immediately or after all queued write requests are flushed.
    `protected abstract ByteBuffer` | `convertToDirectBuffer(WriteRequest writeRequest, boolean createNew)` Copy the HeapBuffer into a DirectBuffer, if needed.
    `WriteRequest` | `enqueueWriteRequest(WriteRequest writeRequest)` Internal method for enqueue write request after filter chain processing
    `abstract void` | `flushWriteQueue()`
    `Queue<WriteRequest>` | `getWriteQueue()` Get the `Queue` of this session.
    `protected boolean` | `isRegisteredForWrite()`
    `void` | `processWrite(SelectorLoop selectorLoop)` Process a write operation.
    `void` | `setNotRegisteredForWrite()`
    `protected abstract int` | `writeDirect(Object message)` Writes the message immediately.

    - ### Methods inherited from class org.apache.mina.session.AbstractIoSession

      `callReadNextFilter, callWriteNextFilter, changeState, getAttribute, getAttribute, getAttributeKeys, getCreationTime, getId, getLastIoTime, getLastReadTime, getLastWriteTime, getReadBytes, getService, getWrittenBytes, incrementWrittenBytes, initSecure, isClosed, isClosing, isConnected, isConnectedSecured, isCreated, isSecured, isSecuring, processException, processMessageReceived, processMessageSent, processMessageWriting, processSessionClosed, processSessionIdle, processSessionOpen, removeAttribute, setAttribute, setSecured, toString, write, writeWithFuture`

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

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

    - ### Methods inherited from interface org.apache.mina.api.IoSession

      `getConfig, getLocalAddress, getRemoteAddress, isReadSuspended, isWriteSuspended, resumeRead, resumeWrite, suspendRead, suspendWrite`

- - ### Field Detail

    - #### channel

          protected final SelectableChannel channel

      the NIO channel for this session

  - ### Constructor Detail

    - #### AbstractNioSession

          public AbstractNioSession(IoService service,
                            SelectableChannel channel,
                            IdleChecker idleChecker)

  - ### Method Detail

    - #### writeDirect

          protected abstract int writeDirect(Object message)

      Writes the message immediately. If we can't write all the message, we will get back the number of written bytes.
      Parameters:
        `message` - the message to write
      Returns:
        the number of written bytes

    - #### convertToDirectBuffer

          protected abstract ByteBuffer convertToDirectBuffer(WriteRequest writeRequest,
                                         boolean createNew)

      Copy the HeapBuffer into a DirectBuffer, if needed.
      Parameters:
        `writeRequest` - The request containing the HeapBuffer
        `createNew` - A flag to force the creation of a DirectBuffer
      Returns:
        A DirectBuffer

    - #### close

          public IoFuture<Void> close(boolean immediately)

      Closes this session immediately or after all queued write requests are flushed. This operation is asynchronous. Wait for the returned `IoFuture` if you want to wait for the session actually closed. Once this method has been called, no incoming request will be accepted.
      Parameters:
        `immediately` - `true` to close this session immediately. `false` to close this session after all queued write requests are flushed.
      Returns:
        A `IoFuture` that will contains the session's state

    - #### channelClose

          protected abstract void channelClose()

      Close the inner socket channel

    - #### enqueueWriteRequest

          public WriteRequest enqueueWriteRequest(WriteRequest writeRequest)

      Internal method for enqueue write request after filter chain processing
      Parameters:
        `writeRequest` - the message to put in the write request
      Returns:
        the created write request

    - #### flushWriteQueue

          public abstract void flushWriteQueue()

    - #### setNotRegisteredForWrite

          public void setNotRegisteredForWrite()

    - #### isRegisteredForWrite

          protected boolean isRegisteredForWrite()

    - #### getWriteQueue

          public Queue<WriteRequest> getWriteQueue()

      Get the `Queue` of this session. The write queue contains the pending writes.
      Returns:
        the write queue of this session

    - #### processWrite

          public void processWrite(SelectorLoop selectorLoop)

      Process a write operation. This will be executed only because the session has something to write into the channel.

Copyright © 2009–2013 Apache MINA Project. All rights reserved.