public abstract class RequestHandler extends Object
UiMessageHandler
Modifier and Type | Field and Description |
---|---|
protected static com.fasterxml.jackson.databind.ObjectMapper |
MAPPER |
Constructor and Description |
---|
RequestHandler(String eventType)
Constructs a request handler instance that will handle events
of the specified type.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
bool(com.fasterxml.jackson.databind.node.ObjectNode node,
String key)
Returns the specified node property as a boolean.
|
protected void |
chain(String eventType,
com.fasterxml.jackson.databind.node.ObjectNode payload)
Allows one request handler to pass the event on to another for
further processing.
|
String |
eventType()
Returns the event type that this handler handles.
|
protected <T> T |
get(Class<T> serviceClass)
Returns an implementation of the specified service class.
|
protected long |
number(com.fasterxml.jackson.databind.node.ObjectNode node,
String key)
Returns the specified node property as a number.
|
abstract void |
process(com.fasterxml.jackson.databind.node.ObjectNode payload)
Processes the incoming message payload from the client.
|
protected void |
sendMessage(com.fasterxml.jackson.databind.node.ObjectNode message)
Sends a message back to the client.
|
protected void |
sendMessage(String eventType,
com.fasterxml.jackson.databind.node.ObjectNode payload)
Sends a message back to the client with the given event type and payload.
|
protected String |
string(com.fasterxml.jackson.databind.node.ObjectNode node,
String key)
Returns the specified node property as a string.
|
protected String |
string(com.fasterxml.jackson.databind.node.ObjectNode node,
String key,
String defValue)
Returns the specified node property as a string, with a default fallback.
|
public RequestHandler(String eventType)
eventType
- type of event that will be handledpublic String eventType()
public abstract void process(com.fasterxml.jackson.databind.node.ObjectNode payload)
payload
- request message payloadprotected <T> T get(Class<T> serviceClass)
T
- type of serviceserviceClass
- service classServiceNotFoundException
- if no implementation foundprotected void sendMessage(String eventType, com.fasterxml.jackson.databind.node.ObjectNode payload)
eventType
- message event typepayload
- message payloadprotected void sendMessage(com.fasterxml.jackson.databind.node.ObjectNode message)
message
- the message to sendprotected void chain(String eventType, com.fasterxml.jackson.databind.node.ObjectNode payload)
eventType
- event typepayload
- message payloadprotected String string(com.fasterxml.jackson.databind.node.ObjectNode node, String key)
node
- message eventkey
- property nameprotected String string(com.fasterxml.jackson.databind.node.ObjectNode node, String key, String defValue)
node
- object nodekey
- property namedefValue
- fallback value if property is absentprotected boolean bool(com.fasterxml.jackson.databind.node.ObjectNode node, String key)
node
- object nodekey
- property nameprotected long number(com.fasterxml.jackson.databind.node.ObjectNode node, String key)
node
- object nodekey
- property name