Top Description Fields Constructors Methods
org.springframework.messaging.simp

public Class SimpAttributes

extends Object
Class Inheritance
Imports
java.util.Map, org.apache.commons.logging.Log, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders, org.springframework.util.Assert, .StringUtils

A wrapper class for access to attributes associated with a SiMP session (e.g. WebSocket session).
Author
Rossen Stoyanchev
Since
4.1

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
public static final String
DESTRUCTION_CALLBACK_NAME_PREFIX

Prefix for the name of session attributes used to store destruction callbacks.

private static final Log
public static final String
SESSION_COMPLETED_NAME

Key set after the session is completed.

public static final String
SESSION_MUTEX_NAME

Key for the mutex session attribute.

private final String

Constructor Summary

AccessConstructor and Description
public
SimpAttributes(String
the id of the associated session
sessionId
,
Map<String, Object>
the attributes
attributes
)

Constructor wrapping the given session attributes map.

Method Summary

Modifier and TypeMethod and Description
private void
public static SimpAttributes
fromMessage(Message<?>
the message to extract session attributes from
message
)

Extract the SiMP session attributes from the given message and wrap them in a SimpAttributes instance.

public Object

Returns:

the current attribute value, or null if not found
getAttribute
(String
the name of the attribute
name
)

Return the value for the attribute of the given name, if any.

public String[]

Returns:

the attribute names as String array, never null
getAttributeNames
()

Retrieve the names of all attributes.

public String

Returns:

the session id as String (never null)
getSessionId
()

Return an id for the associated session.

public Object

Returns:

the session mutex to use (never null)
getSessionMutex
()

Expose the object to synchronize on for the underlying session.

public boolean
isSessionCompleted()

Whether the sessionCompleted() was already invoked.

public void
registerDestructionCallback(String
the name of the attribute to register the callback for
name
,
Runnable
the destruction callback to be executed
callback
)

Register a callback to execute on destruction of the specified attribute.

public void
removeAttribute(String
the name of the attribute
name
)

Remove the attribute of the given name, if it exists.

private void
public void
sessionCompleted()

Invoked when the session is completed.

public void
setAttribute(String
the name of the attribute
name
,
Object
the value for the attribute
value
)

Set the value with the given name replacing an existing value (if any).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesback to summary
private final Map<String, Object> attributes
DESTRUCTION_CALLBACK_NAME_PREFIXback to summary
public static final String DESTRUCTION_CALLBACK_NAME_PREFIX

Prefix for the name of session attributes used to store destruction callbacks.

loggerback to summary
private static final Log logger
SESSION_COMPLETED_NAMEback to summary
public static final String SESSION_COMPLETED_NAME

Key set after the session is completed.

SESSION_MUTEX_NAMEback to summary
public static final String SESSION_MUTEX_NAME

Key for the mutex session attribute.

sessionIdback to summary
private final String sessionId

Constructor Detail

SimpAttributesback to summary
public SimpAttributes(String sessionId, Map<String, Object> attributes)

Constructor wrapping the given session attributes map.

Parameters
sessionId:String

the id of the associated session

attributes:Map<String, Object>

the attributes

Method Detail

executeDestructionCallbacksback to summary
private void executeDestructionCallbacks()
fromMessageback to summary
public static SimpAttributes fromMessage(Message<?> message)

Extract the SiMP session attributes from the given message and wrap them in a SimpAttributes instance.

Parameters
message:Message<?>

the message to extract session attributes from

getAttributeback to summary
public Object getAttribute(String name)

Return the value for the attribute of the given name, if any.

Parameters
name:String

the name of the attribute

Returns:Object

the current attribute value, or null if not found

Annotations
@Nullable
getAttributeNamesback to summary
public String[] getAttributeNames()

Retrieve the names of all attributes.

Returns:String[]

the attribute names as String array, never null

getSessionIdback to summary
public String getSessionId()

Return an id for the associated session.

Returns:String

the session id as String (never null)

getSessionMutexback to summary
public Object getSessionMutex()

Expose the object to synchronize on for the underlying session.

Returns:Object

the session mutex to use (never null)

isSessionCompletedback to summary
public boolean isSessionCompleted()

Whether the sessionCompleted() was already invoked.

registerDestructionCallbackback to summary
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.

Parameters
name:String

the name of the attribute to register the callback for

callback:Runnable

the destruction callback to be executed

removeAttributeback to summary
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.

Parameters
name:String

the name of the attribute

removeDestructionCallbackback to summary
private void removeDestructionCallback(String name)
sessionCompletedback to summary
public void sessionCompleted()

Invoked when the session is completed. Executed completion callbacks.

setAttributeback to summary
public void setAttribute(String name, Object value)

Set the value with the given name replacing an existing value (if any).

Parameters
name:String

the name of the attribute

value:Object

the value for the attribute