Package org.onosproject.ui
Class UiMessageHandler
- java.lang.Object
- 
- org.onosproject.ui.UiMessageHandler
 
- 
 public abstract class UiMessageHandler extends java.lang.ObjectAbstraction of an entity capable of processing JSON messages from the user interface client.The message structure is: { "event": "event-type", "payload": { arbitrary JSON object structure } }Oninitializationthe handler will create and cacheRequestHandlerinstances, each of which are bound to a particular event-type. Onarrivalof a new message, the event-type is determined, and the message dispatched to the corresponding RequestHandler'sprocessmethod.For convenience the implementation includes methods to obtain JSON generating objects (mapper, objectNode, arrayNode) as well as a JsonCodecContext for preparing and digesting messages to the UI client. 
- 
- 
Constructor SummaryConstructors Constructor Description UiMessageHandler()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected com.fasterxml.jackson.databind.node.ArrayNodearrayNode()Returns a freshly minted array node.voidcacheLionBundle(LionBundle bundle)Invoked during initialization to cache any requested localization bundles in the handler's context, so that it may subsequently look up localization strings when composing data for the client.UiConnectionconnection()Returns the user interface connection with which this handler was primed.protected abstract java.util.Collection<RequestHandler>createRequestHandlers()Subclasses must create and return the collection of request handlers for the message types they handle.voiddestroy()Destroys the message handler context.ServiceDirectorydirectory()Returns the service directory with which this handler was primed.protected <T> Tget(java.lang.Class<T> serviceClass)Returns an implementation of the specified service class.protected CodecContextgetJsonCodecContext()Obtain a CodecContext to be used in encoding and decoding objects that have a registered JsonCodec for their class.protected LionBundlegetLionBundle(java.lang.String id)Returns the localization bundle with the given identifier, if we requested to have it cached during initialization; null otherwise.voidinit(UiConnection connection, ServiceDirectory directory)Initializes the handler with the user interface connection and service directory context.java.util.Set<java.lang.String>messageTypes()Returns the set of message types which this handler is capable of processing.protected com.fasterxml.jackson.databind.node.ObjectNodeobjectNode()Returns a freshly minted object node.voidprocess(com.fasterxml.jackson.databind.node.ObjectNode message)Processes a JSON message from the user interface client.java.util.Set<java.lang.String>requiredLionBundles()Returns the set of identifiers for localization bundles that the message handler would like injected into itself, so that it can use those bundles in composing localized data to ship to the client.protected voidsendMessage(com.fasterxml.jackson.databind.node.ObjectNode data)Sends the specified data to the client.
 
- 
- 
- 
Method Detail- 
createRequestHandlersprotected abstract java.util.Collection<RequestHandler> createRequestHandlers() Subclasses must create and return the collection of request handlers for the message types they handle.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.- Returns:
- the message handler instances
 
 - 
messageTypespublic java.util.Set<java.lang.String> messageTypes() Returns the set of message types which this handler is capable of processing.- Returns:
- set of message types
 
 - 
processpublic void process(com.fasterxml.jackson.databind.node.ObjectNode message) Processes a JSON message from the user interface client.- Parameters:
- message- JSON message
 
 - 
initpublic void init(UiConnection connection, ServiceDirectory directory) Initializes the handler with the user interface connection and service directory context.- Parameters:
- connection- user interface connection
- directory- service directory
 
 - 
destroypublic void destroy() Destroys the message handler context.
 - 
connectionpublic UiConnection connection() Returns the user interface connection with which this handler was primed.- Returns:
- user interface connection
 
 - 
directorypublic ServiceDirectory directory() Returns the service directory with which this handler was primed.- Returns:
- service directory
 
 - 
getprotected <T> T get(java.lang.Class<T> serviceClass) Returns an implementation of the specified service class.- Type Parameters:
- T- type of service
- Parameters:
- serviceClass- service class
- Returns:
- implementation class
- Throws:
- ServiceNotFoundException- if no implementation found
 
 - 
requiredLionBundlespublic java.util.Set<java.lang.String> requiredLionBundles() Returns the set of identifiers for localization bundles that the message handler would like injected into itself, so that it can use those bundles in composing localized data to ship to the client.This default implementation returns an empty set. Subclasses that wish to have localization bundles injected should override this method and return the set of bundle identifiers. - Returns:
- the set of identifiers of required localization bundles
 
 - 
cacheLionBundlepublic void cacheLionBundle(LionBundle bundle) Invoked during initialization to cache any requested localization bundles in the handler's context, so that it may subsequently look up localization strings when composing data for the client.- Parameters:
- bundle- the bundle to cache
 
 - 
getLionBundleprotected LionBundle getLionBundle(java.lang.String id) Returns the localization bundle with the given identifier, if we requested to have it cached during initialization; null otherwise.- Parameters:
- id- the lion bundle identifier
- Returns:
- the associated lion bundle
 
 - 
objectNodeprotected com.fasterxml.jackson.databind.node.ObjectNode objectNode() Returns a freshly minted object node.- Returns:
- new object node
 
 - 
arrayNodeprotected com.fasterxml.jackson.databind.node.ArrayNode arrayNode() Returns a freshly minted array node.- Returns:
- new array node
 
 - 
sendMessageprotected void sendMessage(com.fasterxml.jackson.databind.node.ObjectNode data) Sends the specified data to the client. It is expected that the data is in the prescribed JSON format for events to the client.- Parameters:
- data- data to be sent
 
 - 
getJsonCodecContextprotected CodecContext getJsonCodecContext() Obtain a CodecContext to be used in encoding and decoding objects that have a registered JsonCodec for their class. This method instantiates a private inner class which is returned on subsequent calls.- Returns:
- a CodecContext.
 
 
- 
 
-