public class UserRegistryMessageHandler extends java.lang.Object implements MessageHandler, ApplicationListener<BrokerAvailabilityEvent>
MessageHandler
that handles user registry broadcasts from other
application servers and periodically broadcasts the content of the local
user registry.
The aggregated information
is maintained in a MultiServerUserRegistry
.Modifier and Type | Class and Description |
---|---|
private class |
UserRegistryMessageHandler.UserRegistryTask |
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
broadcastDestination |
private SimpMessagingTemplate |
brokerTemplate |
private long |
registryExpirationPeriod |
private java.util.concurrent.ScheduledFuture<?> |
scheduledFuture |
private TaskScheduler |
scheduler |
private UserRegistryMessageHandler.UserRegistryTask |
schedulerTask |
private MultiServerUserRegistry |
userRegistry |
Constructor and Description |
---|
UserRegistryMessageHandler(MultiServerUserRegistry userRegistry,
SimpMessagingTemplate brokerTemplate,
java.lang.String broadcastDestination,
TaskScheduler scheduler)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getBroadcastDestination()
Return the configured destination for broadcasting UserRegistry information.
|
long |
getRegistryExpirationPeriod()
Return the configured registry expiration period.
|
void |
handleMessage(Message<?> message)
Handle the given message.
|
void |
onApplicationEvent(BrokerAvailabilityEvent event)
Handle an application event.
|
void |
setRegistryExpirationPeriod(long milliseconds)
Configure the amount of time (in milliseconds) before a remote user
registry snapshot is considered expired.
|
private final MultiServerUserRegistry userRegistry
private final SimpMessagingTemplate brokerTemplate
private final java.lang.String broadcastDestination
private final TaskScheduler scheduler
private final UserRegistryMessageHandler.UserRegistryTask schedulerTask
private volatile java.util.concurrent.ScheduledFuture<?> scheduledFuture
private long registryExpirationPeriod
public UserRegistryMessageHandler(MultiServerUserRegistry userRegistry, SimpMessagingTemplate brokerTemplate, java.lang.String broadcastDestination, TaskScheduler scheduler)
userRegistry
- the registry with local and remote user registry informationbrokerTemplate
- template for broadcasting local registry informationbroadcastDestination
- the destination to broadcast toscheduler
- public java.lang.String getBroadcastDestination()
public void setRegistryExpirationPeriod(long milliseconds)
By default this is set to 20 seconds (value of 20000).
milliseconds
- the expiration period in millisecondspublic long getRegistryExpirationPeriod()
public void onApplicationEvent(BrokerAvailabilityEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<BrokerAvailabilityEvent>
event
- the event to respond topublic void handleMessage(Message<?> message) throws MessagingException
MessageHandler
handleMessage
in interface MessageHandler
message
- the message to be handledMessagingException