类 SimpAttributes


  • public class SimpAttributes
    extends Object
    A wrapper class for access to attributes associated with a SiMP session (e.g. WebSocket session).
    从以下版本开始:
    4.1
    作者:
    Rossen Stoyanchev
    • 构造器详细资料

      • SimpAttributes

        public SimpAttributes​(String sessionId,
                              Map<String,​Object> attributes)
        Constructor wrapping the given session attributes map.
        参数:
        sessionId - the id of the associated session
        attributes - the attributes
    • 方法详细资料

      • getAttribute

        public Object getAttribute​(String name)
        Return the value for the attribute of the given name, if any.
        参数:
        name - the name of the attribute
        返回:
        the current attribute value, or null if not found
      • setAttribute

        public void setAttribute​(String name,
                                 Object value)
        Set the value with the given name replacing an existing value (if any).
        参数:
        name - the name of the attribute
        value - the value for the attribute
      • removeAttribute

        public void removeAttribute​(String name)
        Remove the attribute of the given name, if it exists.

        Also removes the registered destruction callback for the specified attribute, if any. However it does not execute the callback. It is assumed the removed object will continue to be used and destroyed independently at the appropriate time.

        参数:
        name - the name of the attribute
      • getAttributeNames

        public String[] getAttributeNames()
        Retrieve the names of all attributes.
        返回:
        the attribute names as String array, never null
      • registerDestructionCallback

        public void registerDestructionCallback​(String name,
                                                Runnable callback)
        Register a callback to execute on destruction of the specified attribute. The callback is executed when the session is closed.
        参数:
        name - the name of the attribute to register the callback for
        callback - the destruction callback to be executed
      • getSessionId

        public String getSessionId()
        Return an id for the associated session.
        返回:
        the session id as String (never null)
      • getSessionMutex

        public Object getSessionMutex()
        Expose the object to synchronize on for the underlying session.
        返回:
        the session mutex to use (never null)
      • sessionCompleted

        public void sessionCompleted()
        Invoked when the session is completed. Executed completion callbacks.
      • fromMessage

        public static SimpAttributes fromMessage​(Message<?> message)
        Extract the SiMP session attributes from the given message and wrap them in a SimpAttributes instance.
        参数:
        message - the message to extract session attributes from