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
 boolean containsAttribute(IoSession session, java.lang.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.
 java.lang.Object getAttribute(IoSession session, java.lang.Object key, java.lang.Object defaultValue)
          Returns the value of user defined attribute associated with the specified key.
 java.util.Set<java.lang.Object> getAttributeKeys(IoSession session)
          Returns the set of keys of all user-defined attributes.
 java.lang.Object removeAttribute(IoSession session, java.lang.Object key)
          Removes a user-defined attribute with the specified key.
 boolean removeAttribute(IoSession session, java.lang.Object key, java.lang.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, java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
          Replaces a user defined attribute with the specified key if the value of the attribute is equals to the specified old value.
 java.lang.Object setAttribute(IoSession session, java.lang.Object key, java.lang.Object value)
          Sets a user-defined attribute.
 java.lang.Object setAttributeIfAbsent(IoSession session, java.lang.Object key, java.lang.Object value)
          Sets a user defined attribute if the attribute with the specified key is not set yet.
 

Method Detail

getAttribute

java.lang.Object getAttribute(IoSession session,
                              java.lang.Object key,
                              java.lang.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

java.lang.Object setAttribute(IoSession session,
                              java.lang.Object key,
                              java.lang.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

java.lang.Object setAttributeIfAbsent(IoSession session,
                                      java.lang.Object key,
                                      java.lang.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

java.lang.Object removeAttribute(IoSession session,
                                 java.lang.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,
                        java.lang.Object key,
                        java.lang.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,
                         java.lang.Object key,
                         java.lang.Object oldValue,
                         java.lang.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,
                          java.lang.Object key)
Returns true if this session contains the attribute with the specified key.


getAttributeKeys

java.util.Set<java.lang.Object> getAttributeKeys(IoSession session)
Returns the set of keys of all user-defined attributes.


dispose

void dispose(IoSession session)
             throws java.lang.Exception
Disposes any releases associated with the specified session. This method is invoked on disconnection.

Throws:
java.lang.Exception


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