Interface IoSessionAttributeMap
- All Known Implementing Classes:
DefaultIoSessionDataStructureFactory.DefaultIoSessionAttributeMap
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.-
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsAttribute(IoSession session, Object key) voidDisposes any releases associated with the specified session.getAttribute(IoSession session, Object key, Object defaultValue) getAttributeKeys(IoSession session) removeAttribute(IoSession session, Object key) Removes a user-defined attribute with the specified key.booleanremoveAttribute(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.booleanreplaceAttribute(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.setAttribute(IoSession session, Object key, Object value) Sets a user-defined attribute.setAttributeIfAbsent(IoSession session, Object key, Object value) Sets a user defined attribute if the attribute with the specified key is not set yet.
-
Method Details
-
getAttribute
- 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
-
setAttributeIfAbsent
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); }- 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
-
removeAttribute
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; }- 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
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; }- 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
-
getAttributeKeys
-
dispose
-