Class RequestHandler

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static com.fasterxml.jackson.databind.ObjectMapper MAPPER  
    • Constructor Summary

      Constructors 
      Constructor Description
      RequestHandler​(java.lang.String eventType)
      Constructs a request handler instance that will handle events of the specified type.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAPPER

        protected static final com.fasterxml.jackson.databind.ObjectMapper MAPPER
    • Constructor Detail

      • RequestHandler

        public RequestHandler​(java.lang.String eventType)
        Constructs a request handler instance that will handle events of the specified type.
        Parameters:
        eventType - type of event that will be handled
    • Method Detail

      • eventType

        public java.lang.String eventType()
        Returns the event type that this handler handles.
        Returns:
        event type
      • process

        public abstract void process​(com.fasterxml.jackson.databind.node.ObjectNode payload)
        Processes the incoming message payload from the client.
        Parameters:
        payload - request message payload
      • get

        protected <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
      • sendMessage

        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.
        Parameters:
        eventType - message event type
        payload - message payload
      • sendMessage

        protected void sendMessage​(com.fasterxml.jackson.databind.node.ObjectNode message)
        Sends a message back to the client. Here, the message is preformatted; the assumption is that it has its "event" (event type) and "payload" attributes already filled in.
        Parameters:
        message - the message to send
      • chain

        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. Note that the message handlers must be defined in the same parent.
        Parameters:
        eventType - event type
        payload - message payload
      • string

        protected java.lang.String string​(com.fasterxml.jackson.databind.node.ObjectNode node,
                                          java.lang.String key)
        Returns the specified node property as a string.
        Parameters:
        node - message event
        key - property name
        Returns:
        property as a string
      • 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.
        Parameters:
        node - object node
        key - property name
        defValue - fallback value if property is absent
        Returns:
        property as a string
      • bool

        protected boolean bool​(com.fasterxml.jackson.databind.node.ObjectNode node,
                               java.lang.String key)
        Returns the specified node property as a boolean. More precisely, if the value for the given key is the string "true" then this returns true, false otherwise.
        Parameters:
        node - object node
        key - property name
        Returns:
        property as a boolean
      • number

        protected long number​(com.fasterxml.jackson.databind.node.ObjectNode node,
                              java.lang.String key)
        Returns the specified node property as a number.
        Parameters:
        node - object node
        key - property name
        Returns:
        property as a number