org.apache.mina.session

## Class AbstractIoSession

- java.lang.Object
- - org.apache.mina.session.AbstractIoSession

- All Implemented Interfaces:
    IoSession, ReadFilterChainController, WriteFilterChainController
  Direct Known Subclasses:
    AbstractNioSession, BioUdpSession

      public abstract class AbstractIoSession
      extends Object
      implements IoSession, ReadFilterChainController, WriteFilterChainController

  Base implementation of `IoSession` shared with all the different transports.
  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 IoSessionConfig` | `config` The session config
    `protected IdleChecker` | `idleChecker` the `IdleChecker` in charge of detecting idle event for this session
    `protected boolean` | `secured` Tells if the session is secured or not
    `protected IoSession.SessionState` | `state` The session's state : one of CREATED, CONNECTED, CLOSING, CLOSED, SECURING, CONNECTED_SECURED

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

      `SSL_HELPER`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractIoSession(IoService service, IdleChecker idleChecker)` Create an `IoSession` with a unique identifier ( `IoSession.getId()`) and an associated `IoService`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `callReadNextFilter(Object message)`
    `void` | `callWriteNextFilter(WriteRequest message)` process session message received event using the filter chain.
    `void` | `changeState(IoSession.SessionState to)` Changes the session's state from the current state to a new state.
    `<T> T` | `getAttribute(AttributeKey<T> key)` Returns the value of the user-defined attribute for the given `key`.If the there is no attribute with the specified key `null` will be returned.
    `<T> T` | `getAttribute(AttributeKey<T> key, T defaultValue)` Returns the value of the user-defined attribute for the given `key`.If the there is no attribute with the specified key the `defaultValue` will be returned.
    `Set<AttributeKey<?>>` | `getAttributeKeys()` Returns an unmodifiable `Set` of all Keys of this `IoSession`.
    `long` | `getCreationTime()` The session's creation time.
    `long` | `getId()` The unique identifier of this session.
    `long` | `getLastIoTime()` Returns the time in millisecond when I/O occurred lastly (either read or write).
    `long` | `getLastReadTime()` Returns the time in millisecond when the last I/O read occurred.
    `long` | `getLastWriteTime()` Returns the time in millisecond when the last I/O write occurred.
    `long` | `getReadBytes()` Gets the total number of bytes read for this session since it was created.
    `IoService` | `getService()` Gets the service this session is attached to.
    `long` | `getWrittenBytes()` Gets the total number of bytes written for this session since it was created.
    `void` | `incrementWrittenBytes(int bytesCount)` To be called by the internal plumber when some bytes are written on the socket
    `void` | `initSecure(SSLContext sslContext)` Initializes the SSL/TLS environment for this session.
    `boolean` | `isClosed()` Tells if the session is currently closed.
    `boolean` | `isClosing()` Tells if the session is being closed.
    `boolean` | `isConnected()` Tells if the session is currently connected and able to process incoming requests and to send outgoing responses.
    `boolean` | `isConnectedSecured()` Tells if the session is using SSL/TLS.
    `boolean` | `isCreated()` Tells if the session is created.
    `boolean` | `isSecured()` Tells if the session is belonging to a secured connection.
    `boolean` | `isSecuring()` Tells if the session is processing a SSL/TLS handshake.
    `protected void` | `processException(Exception t)` send a caught exception to the `IoHandler` (if any)
    `void` | `processMessageReceived(ByteBuffer message)` process session message received event using the filter chain.
    `void` | `processMessageSent(Object highLevelMessage)`
    `void` | `processMessageWriting(WriteRequest writeRequest, IoFuture<Void> future)` process session message writing event using the filter chain.
    `void` | `processSessionClosed()` process session closed event using the filter chain.
    `void` | `processSessionIdle(IdleStatus status)` process session idle event using the filter chain.
    `void` | `processSessionOpen()` process session open event using the filter chain.
    `<T> T` | `removeAttribute(AttributeKey<T> key)` Removes the specified Attribute from this container.
    `<T> T` | `setAttribute(AttributeKey<? extends T> key, T value)` Sets a user-defined attribute.
    `void` | `setSecured(boolean secured)`
    `String` | `toString()`
    `void` | `write(Object message)` Enqueue a message for writing.
    `IoFuture<Void>` | `writeWithFuture(Object message)` Same as `IoSession.write(Object)`, but provide a `IoFuture` for tracking the completion of this write.

    - ### 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

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

- - ### Field Detail

    - #### idleChecker

          protected final IdleChecker idleChecker

      the `IdleChecker` in charge of detecting idle event for this session

    - #### config

          protected IoSessionConfig config

      The session config

    - #### state

          protected volatile IoSession.SessionState state

      The session's state : one of CREATED, CONNECTED, CLOSING, CLOSED, SECURING, CONNECTED_SECURED

    - #### secured

          protected volatile boolean secured

      Tells if the session is secured or not

  - ### Constructor Detail

    - #### AbstractIoSession

          public AbstractIoSession(IoService service,
                           IdleChecker idleChecker)

      Create an `IoSession` with a unique identifier ( `IoSession.getId()`) and an associated `IoService`
      Parameters:
        `service` - the service this session is associated with
        `idleChecker` - the checker for idle session

  - ### Method Detail

    - #### isClosed

          public boolean isClosed()

      Tells if the session is currently closed.
      Specified by:
        `isClosed` in interface `IoSession`
      Returns:
        `true` if this session is disconnected with remote peer.

    - #### isClosing

          public boolean isClosing()

      Tells if the session is being closed.
      Specified by:
        `isClosing` in interface `IoSession`
      Returns:
        `true` if this session is in the process of being closed.

    - #### isConnected

          public boolean isConnected()

      Tells if the session is currently connected and able to process incoming requests and to send outgoing responses.
      Specified by:
        `isConnected` in interface `IoSession`
      Returns:
        `true` if this session is connected with remote peer.

    - #### isCreated

          public boolean isCreated()

      Tells if the session is created.
      Specified by:
        `isCreated` in interface `IoSession`
      Returns:
        `true` if this session is created.

    - #### isSecuring

          public boolean isSecuring()

      Tells if the session is processing a SSL/TLS handshake.
      Specified by:
        `isSecuring` in interface `IoSession`
      Returns:
        `true if and only if this session is processing a SSL/TLS handshake.`

    - #### isConnectedSecured

          public boolean isConnectedSecured()

      Tells if the session is using SSL/TLS.
      Specified by:
        `isConnectedSecured` in interface `IoSession`
      Returns:
        `true if and only if this session is exchanging data over a SSL/TLS connection`

    - #### changeState

          public void changeState(IoSession.SessionState to)

      Changes the session's state from the current state to a new state. Not all the transition are allowed. Here is the list of all the possible transitions :
      - CREATED -> CONNECTED
      - CREATED -> SECURING
      - CREATED -> CLOSING
      - CONNECTED -> SECURING
      - CONNECTED -> CLOSING
      - SECURING -> SECURED
      - SECURING -> CLOSING
      - SECURED -> CONNECTED
      - SECURED -> SECURING
      - SECURED -> CLOSING
      - CLOSING -> CLOSED
      Specified by:
        `changeState` in interface `IoSession`
      Parameters:
        `to` - The final SessionState

    - #### isSecured

          public boolean isSecured()

      Tells if the session is belonging to a secured connection.
      Specified by:
        `isSecured` in interface `IoSession`
      Returns:
        `true if and only if this session is belonging a secured connection.`

    - #### setSecured

          public void setSecured(boolean secured)

    - #### initSecure

          public void initSecure(SSLContext sslContext)

      Initializes the SSL/TLS environment for this session.
      Specified by:
        `initSecure` in interface `IoSession`
      Parameters:
        `sslContext` - The SLLCOntext instance to use.

    - #### getId

          public long getId()

      The unique identifier of this session.
      Specified by:
        `getId` in interface `IoSession`
      Returns:
        the session's unique identifier

    - #### getCreationTime

          public long getCreationTime()

      The session's creation time.
      Specified by:
        `getCreationTime` in interface `IoSession`
      Returns:
        the session's creation time in milliseconds

    - #### getReadBytes

          public long getReadBytes()

      Gets the total number of bytes read for this session since it was created. Returns the total number of bytes which were read from this session.
      Specified by:
        `getReadBytes` in interface `IoSession`

    - #### incrementWrittenBytes

          public void incrementWrittenBytes(int bytesCount)

      To be called by the internal plumber when some bytes are written on the socket
      Parameters:
        `bytesCount` - number of extra bytes written

    - #### getWrittenBytes

          public long getWrittenBytes()

      Gets the total number of bytes written for this session since it was created.
      Specified by:
        `getWrittenBytes` in interface `IoSession`
      Returns:
        the total number of bytes which were written to this session.

    - #### getLastReadTime

          public long getLastReadTime()

      Returns the time in millisecond when the last I/O read occurred. Returns the time in millisecond when read operation occurred lastly.
      Specified by:
        `getLastReadTime` in interface `IoSession`

    - #### getLastWriteTime

          public long getLastWriteTime()

      Returns the time in millisecond when the last I/O write occurred. Returns the time in millisecond when write operation occurred lastly.
      Specified by:
        `getLastWriteTime` in interface `IoSession`

    - #### getLastIoTime

          public final long getLastIoTime()

      Returns the time in millisecond when I/O occurred lastly (either read or write).
      Specified by:
        `getLastIoTime` in interface `IoSession`
      Returns:
        the time of the last read or write done for this session

    - #### getService

          public IoService getService()

      Gets the service this session is attached to.
      Specified by:
        `getService` in interface `IoSession`
      Returns:
        the `IoService` which provides `IoSession` to this session.

    - #### getAttribute

          public final <T> T getAttribute(AttributeKey<T> key,
                           T defaultValue)

      Returns the value of the user-defined attribute for the given `key`.If the there is no attribute with the specified key the `defaultValue` will be returned.
      Specified by:
        `getAttribute` in interface `IoSession`
      Parameters:
        `key` - the attribute's key, must not be `null`
      Returns:
        `defaultValue` if there is no attribute with the specified key
      Throws:
        `IllegalArgumentException` - if `key==null`
      See Also:
        `setAttribute(AttributeKey, Object)`

    - #### getAttribute

          public final <T> T getAttribute(AttributeKey<T> key)

      Returns the value of the user-defined attribute for the given `key`.If the there is no attribute with the specified key `null` will be returned.
      Specified by:
        `getAttribute` in interface `IoSession`
      Parameters:
        `key` - the attribute's key, must not be `null`
      Returns:
        `null` if there is no attribute with the specified key
      Throws:
        `IllegalArgumentException` - if `key==null`
      See Also:
        `setAttribute(AttributeKey, Object)`

    - #### setAttribute

          public final <T> T setAttribute(AttributeKey<? extends T> key,
                           T value)

      Sets a user-defined attribute. If the `value` is `null` the attribute will be removed from this `IoSession`.
      Specified by:
        `setAttribute` in interface `IoSession`
      Parameters:
        `key` - the attribute's key, must not be `null`
        `value` - the attribute's value, `null` to remove the attribute
      Returns:
        the old attribute's value or `null` if there is no previous value
      Throws:
        `IllegalArgumentException` -
        - if `key==null`
        - if `value` is not `null` and not an instance of type that is specified in by the given `key` (see `AttributeKey.getType()`)
      See Also:
        `getAttribute(AttributeKey)`

    - #### getAttributeKeys

          public Set<AttributeKey<?>> getAttributeKeys()

      Returns an unmodifiable `Set` of all Keys of this `IoSession`. If this `IoSession` contains no attributes an empty `Set` will be returned.
      Specified by:
        `getAttributeKeys` in interface `IoSession`
      Returns:
        all Keys, never `null`
      See Also:
        `Collections.unmodifiableSet(Set)`

    - #### removeAttribute

          public <T> T removeAttribute(AttributeKey<T> key)

      Removes the specified Attribute from this container. The old value will be returned, `null` will be rutrnen if there is no such attribute in this container.
      This method is equivalent to `setAttribute(key,null)`.
      Specified by:
        `removeAttribute` in interface `IoSession`
      Parameters:
        `key` - of the attribute to be removed,must not be `null`
      Returns:
        the removed value, `null` if this container doesn't contain the specified attribute
      Throws:
        `IllegalArgumentException` - if `key==null`

    - #### write

          public void write(Object message)

      Enqueue a message for writing. This method wont block ! The message will by asynchronously processed by the filter chain and wrote to socket by the `SelectorLoop`
      Specified by:
        `write` in interface `IoSession`

    - #### writeWithFuture

          public IoFuture<Void> writeWithFuture(Object message)

      Same as `IoSession.write(Object)`, but provide a `IoFuture` for tracking the completion of this write.
      Specified by:
        `writeWithFuture` in interface `IoSession`
      Parameters:
        `message` - the message to be processed and written
      Returns:
        the `IoFuture` for tracking this asynchronous operation

    - #### processException

          protected void processException(Exception t)

      send a caught exception to the `IoHandler` (if any)

    - #### processSessionOpen

          public void processSessionOpen()

      process session open event using the filter chain. To be called by the session `SelectorLoop` .

    - #### processSessionClosed

          public void processSessionClosed()

      process session closed event using the filter chain. To be called by the session `SelectorLoop` .

    - #### processSessionIdle

          public void processSessionIdle(IdleStatus status)

      process session idle event using the filter chain. To be called by the session `SelectorLoop` .

    - #### processMessageReceived

          public void processMessageReceived(ByteBuffer message)

      process session message received event using the filter chain. To be called by the session `SelectorLoop` .
      Parameters:
        `message` - the received message

    - #### processMessageWriting

          public void processMessageWriting(WriteRequest writeRequest,
                                   IoFuture<Void> future)

      process session message writing event using the filter chain. To be called by the session `SelectorLoop` .
      Parameters:
        `message` - the wrote message, should be transformed into ByteBuffer at the end of the filter chain

    - #### processMessageSent

          public void processMessageSent(Object highLevelMessage)

    - #### callWriteNextFilter

          public void callWriteNextFilter(WriteRequest message)

      process session message received event using the filter chain. To be called by the session `SelectorLoop` .
      Specified by:
        `callWriteNextFilter` in interface `WriteFilterChainController`
      Parameters:
        `message` - the received message

    - #### callReadNextFilter

          public void callReadNextFilter(Object message)

      Specified by:
        `callReadNextFilter` in interface `ReadFilterChainController`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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