Top Description Inners Fields Constructors Methods
org.springframework.web.socket.messaging

public Class DefaultSimpUserRegistry

extends Object
implements SimpUserRegistry, SmartApplicationListener
Class Inheritance
All Implemented Interfaces
org.springframework.context.event.SmartApplicationListener, org.springframework.core.Ordered, org.springframework.context.ApplicationListener, java.util.EventListener, org.springframework.messaging.simp.user.SimpUserRegistry
Imports
java.security.Principal, java.util.HashSet, .Map, .Set, java.util.concurrent.ConcurrentHashMap, org.springframework.context.ApplicationEvent, org.springframework.context.event.SmartApplicationListener, org.springframework.core.Ordered, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders, org.springframework.messaging.simp.SimpMessageHeaderAccessor, org.springframework.messaging.simp.user.DestinationUserNameProvider, .SimpSession, .SimpSubscription, .SimpSubscriptionMatcher, .SimpUser, .SimpUserRegistry, org.springframework.util.Assert

A default implementation of SimpUserRegistry that relies on AbstractSubProtocolEvent application context events to keep track of connected users and their subscriptions.
Authors
Rossen Stoyanchev, Sam Brannen
Since
4.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private int
private final Object
private final Map<String, DefaultSimpUserRegistry.LocalSimpSession>
private final Map<String, DefaultSimpUserRegistry.LocalSimpUser>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Set<SimpSubscription>
findSubscriptions(SimpSubscriptionMatcher
the matcher to use
matcher
)

Implements org.springframework.messaging.simp.user.SimpUserRegistry.findSubscriptions.

Find subscriptions with the given matcher.

public int
getOrder()

Overrides default org.springframework.context.event.SmartApplicationListener.getOrder.

Determine this listener's order in a set of listeners for the same event.

public SimpUser
getUser(String
the name of the user to look up
userName
)

Implements org.springframework.messaging.simp.user.SimpUserRegistry.getUser.

Get the user for the given name.

public int
getUserCount()

Implements org.springframework.messaging.simp.user.SimpUserRegistry.getUserCount.

Return the count of all connected users.

public Set<SimpUser>
getUsers()

Implements org.springframework.messaging.simp.user.SimpUserRegistry.getUsers.

Return a snapshot of all connected users.

public void
onApplicationEvent(ApplicationEvent
the event to respond to
event
)

Implements org.springframework.context.ApplicationListener.onApplicationEvent.

Handle an application event.

public void
setOrder(int order)

Specify the order value for this registry.

public boolean
supportsEventType(Class<? extends ApplicationEvent>
the event type (never null)
eventType
)

Implements org.springframework.context.event.SmartApplicationListener.supportsEventType.

Determine whether this listener actually supports the given event type.

public boolean
supportsSourceType(Class<?>
the source type, or null if no source
sourceType
)

Overrides default org.springframework.context.event.SmartApplicationListener.supportsSourceType.

Determine whether this listener actually supports the given source type.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

orderback to summary
private int order
sessionLockback to summary
private final Object sessionLock
sessionsback to summary
private final Map<String, DefaultSimpUserRegistry.LocalSimpSession> sessions
usersback to summary
private final Map<String, DefaultSimpUserRegistry.LocalSimpUser> users

Constructor Detail

DefaultSimpUserRegistryback to summary
public DefaultSimpUserRegistry()

Method Detail

findSubscriptionsback to summary
public Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher)

Implements org.springframework.messaging.simp.user.SimpUserRegistry.findSubscriptions.

Doc from org.springframework.messaging.simp.user.SimpUserRegistry.findSubscriptions.

Find subscriptions with the given matcher.

Parameters
matcher:SimpSubscriptionMatcher

the matcher to use

Returns:Set<SimpSubscription>

a set of matching subscriptions, or an empty set if none

Annotations
@Override
getOrderback to summary
public int getOrder()

Overrides default org.springframework.context.event.SmartApplicationListener.getOrder.

Doc from org.springframework.context.event.SmartApplicationListener.getOrder.

Determine this listener's order in a set of listeners for the same event.

The default implementation returns LOWEST_PRECEDENCE.

Returns:int

Doc from org.springframework.core.Ordered.getOrder.

the order value

Annotations
@Override
getUserback to summary
public SimpUser getUser(String userName)

Implements org.springframework.messaging.simp.user.SimpUserRegistry.getUser.

Doc from org.springframework.messaging.simp.user.SimpUserRegistry.getUser.

Get the user for the given name.

Parameters
userName:String

the name of the user to look up

Returns:SimpUser

the user, or null if not connected

Annotations
@Override
@Nullable
getUserCountback to summary
public int getUserCount()

Implements org.springframework.messaging.simp.user.SimpUserRegistry.getUserCount.

Doc from org.springframework.messaging.simp.user.SimpUserRegistry.getUserCount.

Return the count of all connected users.

Returns:int

the number of connected users

Annotations
@Override
getUsersback to summary
public Set<SimpUser> getUsers()

Implements org.springframework.messaging.simp.user.SimpUserRegistry.getUsers.

Doc from org.springframework.messaging.simp.user.SimpUserRegistry.getUsers.

Return a snapshot of all connected users.

The returned set is a copy and will not reflect further changes.

Returns:Set<SimpUser>

the connected users, or an empty set if none

Annotations
@Override
onApplicationEventback to summary
public void onApplicationEvent(ApplicationEvent event)

Implements org.springframework.context.ApplicationListener.onApplicationEvent.

Doc from org.springframework.context.ApplicationListener.onApplicationEvent.

Handle an application event.

Parameters
event:ApplicationEvent

the event to respond to

Annotations
@Override
setOrderback to summary
public void setOrder(int order)

Specify the order value for this registry.

Default is Ordered#LOWEST_PRECEDENCE.

Since
5.0.8
supportsEventTypeback to summary
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType)

Implements org.springframework.context.event.SmartApplicationListener.supportsEventType.

Doc from org.springframework.context.event.SmartApplicationListener.supportsEventType.

Determine whether this listener actually supports the given event type.

Parameters
eventType:Class<? extends ApplicationEvent>

the event type (never null)

Annotations
@Override
supportsSourceTypeback to summary
public boolean supportsSourceType(Class<?> sourceType)

Overrides default org.springframework.context.event.SmartApplicationListener.supportsSourceType.

Doc from org.springframework.context.event.SmartApplicationListener.supportsSourceType.

Determine whether this listener actually supports the given source type.

The default implementation always returns true.

Parameters
sourceType:Class<?>

the source type, or null if no source

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.web.socket.messaging back to summary

private Class DefaultSimpUserRegistry.LocalSimpSession

extends Object
implements SimpSession
Class Inheritance
  • java.lang.Object
  • org.springframework.web.socket.messaging.DefaultSimpUserRegistry.LocalSimpSession
All Implemented Interfaces
org.springframework.messaging.simp.user.SimpSession

Field Summary

Modifier and TypeField and Description
private final String
private final Map<String, SimpSubscription>
private final DefaultSimpUserRegistry.LocalSimpUser

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addSubscription(String id, String destination)

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
public Set<SimpSubscription>
getSubscriptions()

Implements org.springframework.messaging.simp.user.SimpSession.getSubscriptions.

Return the subscriptions for this session.

public DefaultSimpUserRegistry.LocalSimpUser
getUser()

Implements org.springframework.messaging.simp.user.SimpSession.getUser.

Return the user associated with the session.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

idback to summary
private final String id
subscriptionsback to summary
private final Map<String, SimpSubscription> subscriptions
userback to summary
private final DefaultSimpUserRegistry.LocalSimpUser user

Constructor Detail

LocalSimpSessionback to summary
public LocalSimpSession(String id, DefaultSimpUserRegistry.LocalSimpUser user)

Method Detail

addSubscriptionback to summary
pack-priv void addSubscription(String id, String destination)
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getIdback to summary
public String getId()

Implements org.springframework.messaging.simp.user.SimpSession.getId.

Doc from org.springframework.messaging.simp.user.SimpSession.getId.

Return the session id.

Annotations
@Override
getSubscriptionsback to summary
public Set<SimpSubscription> getSubscriptions()

Implements org.springframework.messaging.simp.user.SimpSession.getSubscriptions.

Doc from org.springframework.messaging.simp.user.SimpSession.getSubscriptions.

Return the subscriptions for this session.

Annotations
@Override
getUserback to summary
public DefaultSimpUserRegistry.LocalSimpUser getUser()

Implements org.springframework.messaging.simp.user.SimpSession.getUser.

Doc from org.springframework.messaging.simp.user.SimpSession.getUser.

Return the user associated with the session.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
removeSubscriptionback to summary
pack-priv void removeSubscription(String id)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.web.socket.messaging back to summary

private Class DefaultSimpUserRegistry.LocalSimpSubscription

extends Object
implements SimpSubscription
Class Inheritance
  • java.lang.Object
  • org.springframework.web.socket.messaging.DefaultSimpUserRegistry.LocalSimpSubscription
All Implemented Interfaces
org.springframework.messaging.simp.user.SimpSubscription

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final DefaultSimpUserRegistry.LocalSimpSession

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
public String
getId()

Implements org.springframework.messaging.simp.user.SimpSubscription.getId.

Return the id associated of the subscription.

public DefaultSimpUserRegistry.LocalSimpSession
getSession()

Implements org.springframework.messaging.simp.user.SimpSubscription.getSession.

Return the session of the subscription.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

destinationback to summary
private final String destination
idback to summary
private final String id
sessionback to summary
private final DefaultSimpUserRegistry.LocalSimpSession session

Constructor Detail

LocalSimpSubscriptionback to summary
public LocalSimpSubscription(String id, String destination, DefaultSimpUserRegistry.LocalSimpSession session)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDestinationback to summary
public String getDestination()

Implements org.springframework.messaging.simp.user.SimpSubscription.getDestination.

Doc from org.springframework.messaging.simp.user.SimpSubscription.getDestination.

Return the subscription's destination.

Annotations
@Override
getIdback to summary
public String getId()

Implements org.springframework.messaging.simp.user.SimpSubscription.getId.

Doc from org.springframework.messaging.simp.user.SimpSubscription.getId.

Return the id associated of the subscription.

Annotations
@Override
getSessionback to summary
public DefaultSimpUserRegistry.LocalSimpSession getSession()

Implements org.springframework.messaging.simp.user.SimpSubscription.getSession.

Doc from org.springframework.messaging.simp.user.SimpSubscription.getSession.

Return the session of the subscription.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.web.socket.messaging back to summary

private Class DefaultSimpUserRegistry.LocalSimpUser

extends Object
implements SimpUser
Class Inheritance
  • java.lang.Object
  • org.springframework.web.socket.messaging.DefaultSimpUserRegistry.LocalSimpUser
All Implemented Interfaces
org.springframework.messaging.simp.user.SimpUser

Field Summary

Modifier and TypeField and Description
private final String
private final Principal
private final Map<String, SimpSession>

Constructor Summary

AccessConstructor and Description
public
LocalSimpUser(String userName, Principal user)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
public Principal
getPrincipal()

Implements org.springframework.messaging.simp.user.SimpUser.getPrincipal.

Return the user associated with the session, if available.

public SimpSession
getSession(String
the session id
sessionId
)

Implements org.springframework.messaging.simp.user.SimpUser.getSession.

Look up the session for the given id.

public Set<SimpSession>
getSessions()

Implements org.springframework.messaging.simp.user.SimpUser.getSessions.

Return the sessions for the user.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
hasSessions()

Implements org.springframework.messaging.simp.user.SimpUser.hasSessions.

Whether the user has any sessions.

pack-priv void
removeSession(String sessionId)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

nameback to summary
private final String name
userback to summary
private final Principal user
userSessionsback to summary
private final Map<String, SimpSession> userSessions

Constructor Detail

LocalSimpUserback to summary
public LocalSimpUser(String userName, Principal user)

Method Detail

addSessionback to summary
pack-priv void addSession(SimpSession session)
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getNameback to summary
public String getName()

Implements org.springframework.messaging.simp.user.SimpUser.getName.

Doc from org.springframework.messaging.simp.user.SimpUser.getName.

The unique user name.

Annotations
@Override
getPrincipalback to summary
public Principal getPrincipal()

Implements org.springframework.messaging.simp.user.SimpUser.getPrincipal.

Doc from org.springframework.messaging.simp.user.SimpUser.getPrincipal.

Return the user associated with the session, if available. Typically, the user information is available unless the user is connected to a different server in a multi-server user registry scenario.

Annotations
@Nullable
@Override
getSessionback to summary
public SimpSession getSession(String sessionId)

Implements org.springframework.messaging.simp.user.SimpUser.getSession.

Doc from org.springframework.messaging.simp.user.SimpUser.getSession.

Look up the session for the given id.

Parameters
sessionId:String

the session id

Returns:SimpSession

the matching session, or null if none found

Annotations
@Override
@Nullable
getSessionsback to summary
public Set<SimpSession> getSessions()

Implements org.springframework.messaging.simp.user.SimpUser.getSessions.

Doc from org.springframework.messaging.simp.user.SimpUser.getSessions.

Return the sessions for the user. The returned set is a copy and will never be modified.

Returns:Set<SimpSession>

a set of session ids, or an empty set if none

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
hasSessionsback to summary
public boolean hasSessions()

Implements org.springframework.messaging.simp.user.SimpUser.hasSessions.

Doc from org.springframework.messaging.simp.user.SimpUser.hasSessions.

Whether the user has any sessions.

Annotations
@Override
removeSessionback to summary
pack-priv void removeSession(String sessionId)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override