Package jmri.server.json.message
Class JsonMessageClientManager
java.lang.Object
jmri.server.json.message.JsonMessageClientManager
- All Implemented Interfaces:
InstanceManagerAutoDefault
Manager for JSON streaming clients that are subscribing to messages triggered
by out-of-channel events.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) HashMap<String,JsonConnection> (package private) final com.fasterxml.jackson.databind.ObjectMapper -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetClient(JsonConnection connection) Get the first client name associated with a connection.getClients(JsonConnection connection) Get all client names associated with a connection.voidsend(JsonMessage message) Send a message to a client or clients.voidsubscribe(String client, JsonConnection connection) Subscribe to the message service.voidunsubscribe(String client) Cancel the subscription for a single client.voidunsubscribe(JsonConnection connection) Cancel the subscription for all clients on a given connection.
-
Field Details
-
mapper
-
clients
-
-
Constructor Details
-
JsonMessageClientManager
public JsonMessageClientManager()
-
-
Method Details
-
subscribe
Subscribe to the message service.- Parameters:
client- the client identifier to use for the subscriptionconnection- the connection associated with client- Throws:
IllegalArgumentException- if client is already in use for a different connection
-
unsubscribe
Cancel the subscription for a single client.- Parameters:
client- the client canceling the subscription
-
unsubscribe
Cancel the subscription for all clients on a given connection.- Parameters:
connection- the connection canceling the subscription
-
send
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
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
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
-