public abstract class UiMessageHandler extends Object
The message structure is:
{
"type": "event-type",
"payload": {
arbitrary JSON object structure
}
}
On initialization the handler will create and cache
RequestHandler instances, each of which are bound to a particular
event-type. On arrival of a new message,
the event-type is determined, and the message dispatched to the
corresponding RequestHandler's
process method.| Constructor and Description |
|---|
UiMessageHandler() |
| Modifier and Type | Method and Description |
|---|---|
protected com.fasterxml.jackson.databind.node.ArrayNode |
arrayNode()
Returns a freshly minted array node.
|
UiConnection |
connection()
Returns the user interface connection with which this handler was primed.
|
protected abstract Collection<RequestHandler> |
createRequestHandlers()
Subclasses must create and return the collection of request handlers
for the message types they handle.
|
void |
destroy()
Destroys the message handler context.
|
org.onlab.osgi.ServiceDirectory |
directory()
Returns the user interface connection with which this handler was primed.
|
protected <T> T |
get(Class<T> serviceClass)
Returns implementation of the specified service class.
|
void |
init(UiConnection connection,
org.onlab.osgi.ServiceDirectory directory)
Initializes the handler with the user interface connection and
service directory context.
|
Set<String> |
messageTypes()
Returns the set of message types which this handler is capable of
processing.
|
protected com.fasterxml.jackson.databind.node.ObjectNode |
objectNode()
Returns a freshly minted object node.
|
void |
process(com.fasterxml.jackson.databind.node.ObjectNode message)
Processes a JSON message from the user interface client.
|
protected void |
sendMessage(com.fasterxml.jackson.databind.node.ObjectNode data)
Sends the specified data to the client.
|
protected abstract Collection<RequestHandler> createRequestHandlers()
Note that request handlers should be stateless. When we are
destroyed, we will simply drop our references to them
and allow them to be garbage collected.
public Set<String> messageTypes()
public void process(com.fasterxml.jackson.databind.node.ObjectNode message)
message - JSON messagepublic void init(UiConnection connection, org.onlab.osgi.ServiceDirectory directory)
connection - user interface connectiondirectory - service directorypublic void destroy()
public UiConnection connection()
public org.onlab.osgi.ServiceDirectory directory()
protected <T> T get(Class<T> serviceClass)
T - type of serviceserviceClass - service classorg.onlab.osgi.ServiceNotFoundException - if no implementation foundprotected com.fasterxml.jackson.databind.node.ObjectNode objectNode()
protected com.fasterxml.jackson.databind.node.ArrayNode arrayNode()
protected void sendMessage(com.fasterxml.jackson.databind.node.ObjectNode data)
data - data to be sent