org.apache.mina.core.session

## Interface IoSessionAttributeMap

-     public interface IoSessionAttributeMap

  Stores the user-defined attributes which is provided per `IoSession`. All user-defined attribute accesses in `IoSession` are forwarded to the instance of `IoSessionAttributeMap`.
  Author:
    Apache MINA Project

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `containsAttribute(IoSession session, Object key)` Returns `true` if this session contains the attribute with the specified `key`.
    `void` | `dispose(IoSession session)` Disposes any releases associated with the specified session.
    `Object` | `getAttribute(IoSession session, Object key, Object defaultValue)` Returns the value of user defined attribute associated with the specified key.
    `Set<Object>` | `getAttributeKeys(IoSession session)` Returns the set of keys of all user-defined attributes.
    `Object` | `removeAttribute(IoSession session, Object key)` Removes a user-defined attribute with the specified key.
    `boolean` | `removeAttribute(IoSession session, Object key, Object value)` Removes a user defined attribute with the specified key if the current attribute value is equal to the specified value.
    `boolean` | `replaceAttribute(IoSession session, Object key, Object oldValue, Object newValue)` Replaces a user defined attribute with the specified key if the value of the attribute is equals to the specified old value.
    `Object` | `setAttribute(IoSession session, Object key, Object value)` Sets a user-defined attribute.
    `Object` | `setAttributeIfAbsent(IoSession session, Object key, Object value)` Sets a user defined attribute if the attribute with the specified key is not set yet.

- - ### Method Detail

    - #### getAttribute

          Object getAttribute(IoSession session,
                            Object key,
                            Object defaultValue)

      Returns the value of user defined attribute associated with the specified key. If there's no such attribute, the specified default value is associated with the specified key, and the default value is returned. This method is same with the following code except that the operation is performed atomically.

           if (containsAttribute(key)) {
               return getAttribute(key);
           } else {
               setAttribute(key, defaultValue);
               return defaultValue;
           }

    - #### setAttribute

          Object setAttribute(IoSession session,
                            Object key,
                            Object value)

      Sets a user-defined attribute.
      Parameters:
        `key` - the key of the attribute
        `value` - the value of the attribute
      Returns:
        The old value of the attribute. `null` if it is new.

    - #### setAttributeIfAbsent

          Object setAttributeIfAbsent(IoSession session,
                                    Object key,
                                    Object value)

      Sets a user defined attribute if the attribute with the specified key is not set yet. This method is same with the following code except that the operation is performed atomically.

           if (containsAttribute(key)) {
               return getAttribute(key);
           } else {
               return setAttribute(key, value);
           }

    - #### removeAttribute

          Object removeAttribute(IoSession session,
                               Object key)

      Removes a user-defined attribute with the specified key.
      Returns:
        The old value of the attribute. `null` if not found.

    - #### removeAttribute

          boolean removeAttribute(IoSession session,
                                Object key,
                                Object value)

      Removes a user defined attribute with the specified key if the current attribute value is equal to the specified value. This method is same with the following code except that the operation is performed atomically.

           if (containsAttribute(key) && getAttribute(key).equals(value)) {
               removeAttribute(key);
               return true;
           } else {
               return false;
           }

    - #### replaceAttribute

          boolean replaceAttribute(IoSession session,
                                 Object key,
                                 Object oldValue,
                                 Object newValue)

      Replaces a user defined attribute with the specified key if the value of the attribute is equals to the specified old value. This method is same with the following code except that the operation is performed atomically.

           if (containsAttribute(key) && getAttribute(key).equals(oldValue)) {
               setAttribute(key, newValue);
               return true;
           } else {
               return false;
           }

    - #### containsAttribute

          boolean containsAttribute(IoSession session,
                                  Object key)

      Returns `true` if this session contains the attribute with the specified `key`.

    - #### getAttributeKeys

          Set<Object> getAttributeKeys(IoSession session)

      Returns the set of keys of all user-defined attributes.

    - #### dispose

          void dispose(IoSession session)
                       throws Exception

      Disposes any releases associated with the specified session. This method is invoked on disconnection.
      Throws:
        `Exception`

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