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