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 Object implements IoSessionAttributeMap
  • Field Details

  • Constructor Details

    • DefaultIoSessionAttributeMap

      public DefaultIoSessionAttributeMap()
      Default constructor
  • Method Details

    • getAttribute

      public Object getAttribute(IoSession session, Object key, Object defaultValue)
      Specified by:
      getAttribute in interface IoSessionAttributeMap
      Parameters:
      session - the session for which we want to get an attribute
      key - The key we are looking for
      defaultValue - 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 Object setAttribute(IoSession session, Object key, Object value)
      Sets a user-defined attribute.
      Specified by:
      setAttribute in interface IoSessionAttributeMap
      Parameters:
      session - the session for which we want to set an attribute
      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

      public 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);
      }
      
      Specified by:
      setAttributeIfAbsent in interface IoSessionAttributeMap
      Parameters:
      session - the session for which we want to set an attribute
      key - The key we are looking for
      value - The value to inject
      Returns:
      The previous attribute
    • removeAttribute

      public Object removeAttribute(IoSession session, Object key)
      Removes a user-defined attribute with the specified key.
      Specified by:
      removeAttribute in interface IoSessionAttributeMap
      Parameters:
      session - the session for which we want to remove an attribute
      key - The key we are looking for
      Returns:
      The old value of the attribute. null if not found.
    • removeAttribute

      public 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;
      }
      
      Specified by:
      removeAttribute in interface IoSessionAttributeMap
      Parameters:
      session - the session for which we want to remove a value
      key - The key we are looking for
      value - The value to remove
      Returns:
      true if the value has been removed, false if the key was not found of the value not removed
    • replaceAttribute

      public 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;
      }
      
      Specified by:
      replaceAttribute in interface IoSessionAttributeMap
      Parameters:
      session - the session for which we want to replace an attribute
      key - The key we are looking for
      oldValue - The old value to replace
      newValue - The new value to set
      Returns:
      true if the value has been replaced, false if the key was not found of the value not replaced
    • containsAttribute

      public boolean containsAttribute(IoSession session, Object key)
      Specified by:
      containsAttribute in interface IoSessionAttributeMap
      Parameters:
      session - the session for which wa want to check if an attribute is present
      key - The key we are looking for
      Returns:
      true if this session contains the attribute with the specified key.
    • getAttributeKeys

      public Set<Object> getAttributeKeys(IoSession session)
      Specified by:
      getAttributeKeys in interface IoSessionAttributeMap
      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 Exception
      Disposes any releases associated with the specified session. This method is invoked on disconnection.
      Specified by:
      dispose in interface IoSessionAttributeMap
      Parameters:
      session - the session to be disposed
      Throws:
      Exception - If the session can't be disposed