public interface IoSessionAttributeMap
IoSession
.
All user-defined attribute accesses in IoSession
are forwarded to
the instance of IoSessionAttributeMap
.限定符和类型 | 方法和说明 |
---|---|
boolean |
containsAttribute(IoSession session,
java.lang.Object 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) |
java.util.Set<java.lang.Object> |
getAttributeKeys(IoSession session) |
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.
|
java.lang.Object getAttribute(IoSession session, java.lang.Object key, java.lang.Object defaultValue)
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 foundif (containsAttribute(key)) { return getAttribute(key); } else { setAttribute(key, defaultValue); return defaultValue; }
java.lang.Object setAttribute(IoSession session, java.lang.Object key, java.lang.Object value)
session
- the session for which we want to set an attributekey
- the key of the attributevalue
- the value of the attributejava.lang.Object setAttributeIfAbsent(IoSession session, java.lang.Object key, java.lang.Object value)
if (containsAttribute(key)) { return getAttribute(key); } else { return setAttribute(key, value); }
session
- the session for which we want to set an attributekey
- The key we are looking forvalue
- The value to injectjava.lang.Object removeAttribute(IoSession session, java.lang.Object key)
session
- the session for which we want to remove an attributekey
- The key we are looking forboolean removeAttribute(IoSession session, java.lang.Object key, java.lang.Object value)
if (containsAttribute(key) && getAttribute(key).equals(value)) { removeAttribute(key); return true; } else { return false; }
session
- the session for which we want to remove a valuekey
- The key we are looking forvalue
- The value to removeboolean replaceAttribute(IoSession session, java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
if (containsAttribute(key) && getAttribute(key).equals(oldValue)) { setAttribute(key, newValue); return true; } else { return false; }
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 setboolean containsAttribute(IoSession session, java.lang.Object key)
session
- the session for which wa want to check if an attribute is presentkey
- The key we are looking forjava.util.Set<java.lang.Object> getAttributeKeys(IoSession session)
session
- the session for which we want the set of attributesvoid dispose(IoSession session) throws java.lang.Exception
session
- the session to be disposedjava.lang.Exception
- If the session can't be disposed