Package org.apache.mina.core.session
Class DefaultIoSessionDataStructureFactory.DefaultIoSessionAttributeMap
- java.lang.Object
-
- org.apache.mina.core.session.DefaultIoSessionDataStructureFactory.DefaultIoSessionAttributeMap
-
- All Implemented Interfaces:
IoSessionAttributeMap
- Enclosing class:
- DefaultIoSessionDataStructureFactory
private static class DefaultIoSessionDataStructureFactory.DefaultIoSessionAttributeMap extends java.lang.Object implements IoSessionAttributeMap
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentHashMap<java.lang.Object,java.lang.Object>attributes
-
Constructor Summary
Constructors Constructor Description DefaultIoSessionAttributeMap()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsAttribute(IoSession session, java.lang.Object key)voiddispose(IoSession session)Disposes any releases associated with the specified session.java.lang.ObjectgetAttribute(IoSession session, java.lang.Object key, java.lang.Object defaultValue)java.util.Set<java.lang.Object>getAttributeKeys(IoSession session)java.lang.ObjectremoveAttribute(IoSession session, java.lang.Object key)Removes a user-defined attribute with the specified key.booleanremoveAttribute(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.booleanreplaceAttribute(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.ObjectsetAttribute(IoSession session, java.lang.Object key, java.lang.Object value)Sets a user-defined attribute.java.lang.ObjectsetAttributeIfAbsent(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
public java.lang.Object getAttribute(IoSession session, java.lang.Object key, java.lang.Object defaultValue)
- Specified by:
getAttributein interfaceIoSessionAttributeMap- Parameters:
session- the session for which we want to get an attributekey- The key we are looking fordefaultValue- The default returned value if the attribute is not found- 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
public java.lang.Object setAttribute(IoSession session, java.lang.Object key, java.lang.Object value)
Sets a user-defined attribute.- Specified by:
setAttributein interfaceIoSessionAttributeMap- Parameters:
session- the session for which we want to set an attributekey- the key of the attributevalue- the value of the attribute- Returns:
- The old value of the attribute.
nullif it is new.
-
setAttributeIfAbsent
public 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); }- Specified by:
setAttributeIfAbsentin interfaceIoSessionAttributeMap- Parameters:
session- the session for which we want to set an attributekey- The key we are looking forvalue- The value to inject- Returns:
- The previous attribute
-
removeAttribute
public java.lang.Object removeAttribute(IoSession session, java.lang.Object key)
Removes a user-defined attribute with the specified key.- Specified by:
removeAttributein interfaceIoSessionAttributeMap- Parameters:
session- the session for which we want to remove an attributekey- The key we are looking for- Returns:
- The old value of the attribute.
nullif not found.
-
removeAttribute
public 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; }- Specified by:
removeAttributein interfaceIoSessionAttributeMap- Parameters:
session- the session for which we want to remove a valuekey- The key we are looking forvalue- The value to remove- Returns:
trueif the value has been removed,falseif the key was not found of the value not removed
-
replaceAttribute
public 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; }- Specified by:
replaceAttributein interfaceIoSessionAttributeMap- Parameters:
session- the session for which we want to replace an attributekey- The key we are looking foroldValue- The old value to replacenewValue- The new value to set- Returns:
trueif the value has been replaced,falseif the key was not found of the value not replaced
-
containsAttribute
public boolean containsAttribute(IoSession session, java.lang.Object key)
- Specified by:
containsAttributein interfaceIoSessionAttributeMap- Parameters:
session- the session for which wa want to check if an attribute is presentkey- The key we are looking for- Returns:
trueif this session contains the attribute with the specifiedkey.
-
getAttributeKeys
public java.util.Set<java.lang.Object> getAttributeKeys(IoSession session)
- Specified by:
getAttributeKeysin interfaceIoSessionAttributeMap- Parameters:
session- the session for which we want the set of attributes- Returns:
- the set of keys of all user-defined attributes.
-
dispose
public void dispose(IoSession session) throws java.lang.Exception
Disposes any releases associated with the specified session. This method is invoked on disconnection.- Specified by:
disposein interfaceIoSessionAttributeMap- Parameters:
session- the session to be disposed- Throws:
java.lang.Exception- If the session can't be disposed
-
-