Package jmri.server.json.message
Class JsonMessageClientManager
- java.lang.Object
-
- jmri.server.json.message.JsonMessageClientManager
-
- All Implemented Interfaces:
InstanceManagerAutoDefault
public class JsonMessageClientManager extends java.lang.Object implements InstanceManagerAutoDefault
Manager for JSON streaming clients that are subscribing to messages triggered by out-of-channel events.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.HashMap<java.lang.String,JsonConnection>
clients
(package private) com.fasterxml.jackson.databind.ObjectMapper
mapper
-
Constructor Summary
Constructors Constructor Description JsonMessageClientManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getClient(JsonConnection connection)
Get the first client name associated with a connection.java.util.Set<java.lang.String>
getClients(JsonConnection connection)
Get all client names associated with a connection.void
send(JsonMessage message)
Send a message to a client or clients.void
subscribe(java.lang.String client, JsonConnection connection)
Subscribe to the message service.void
unsubscribe(java.lang.String client)
Cancel the subscription for a single client.void
unsubscribe(JsonConnection connection)
Cancel the subscription for all clients on a given connection.
-
-
-
Field Detail
-
mapper
final com.fasterxml.jackson.databind.ObjectMapper mapper
-
clients
java.util.HashMap<java.lang.String,JsonConnection> clients
-
-
Constructor Detail
-
JsonMessageClientManager
public JsonMessageClientManager()
-
-
Method Detail
-
subscribe
public void subscribe(@Nonnull java.lang.String client, @Nonnull JsonConnection connection)
Subscribe to the message service.- Parameters:
client
- the client identifier to use for the subscriptionconnection
- the connection associated with client- Throws:
java.lang.IllegalArgumentException
- if client is already in use for a different connection
-
unsubscribe
public void unsubscribe(@CheckForNull java.lang.String client)
Cancel the subscription for a single client.- Parameters:
client
- the client canceling the subscription
-
unsubscribe
public void unsubscribe(@CheckForNull JsonConnection connection)
Cancel the subscription for all clients on a given connection.- Parameters:
connection
- the connection canceling the subscription
-
send
public void send(@Nonnull JsonMessage message)
Send a message to a client or clients. The determination of a single client or all clients is made usingJsonMessage.getClient()
.- Parameters:
message
- the message to send
-
getClient
@CheckForNull public java.lang.String getClient(@Nonnull JsonConnection connection)
Get the first client name associated with a connection.- Parameters:
connection
- the connection to get a client for- Returns:
- the client or null if the connection is not subscribed
-
getClients
public java.util.Set<java.lang.String> getClients(@Nonnull JsonConnection connection)
Get all client names associated with a connection.- Parameters:
connection
- the connection to get clients for- Returns:
- a set of clients or an empty set if the connection is not subscribed
-
-