Class HttpDownstreamGateway

  • All Implemented Interfaces:
    ca.uqac.lif.azrael.Printable, ca.uqac.lif.azrael.Readable, ca.uqac.lif.cep.Contextualizable, ca.uqac.lif.cep.Duplicable, ca.uqac.lif.cep.DuplicableProcessor

    public class HttpDownstreamGateway
    extends ca.uqac.lif.cep.tmf.Source
    Outputs character strings received over the network from an upstream connection. A HttpDownstreamGateway listens to HTTP requests on a given TCP port. When such a request comes in, it extracts the payload from that request, and pushes it downstream as a String event. Graphically, this processor is represented as:

    Processor graph

    This processor can also be pulled; in such a case, if a pull URL has been specified, the processor sends an HTTP request to that URL, and uses the response's payload as the next event.

    The downstream gateway generally works in tandem with an upstream gateway, which works in reverse.

    Author:
    Sylvain Hallé
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  HttpDownstreamGateway.ListenerCallback  
      • Nested classes/interfaces inherited from class ca.uqac.lif.cep.SynchronousProcessor

        ca.uqac.lif.cep.SynchronousProcessor.InputPushable, ca.uqac.lif.cep.SynchronousProcessor.OutputPullable
      • Nested classes/interfaces inherited from class ca.uqac.lif.cep.Processor

        ca.uqac.lif.cep.Processor.InternalProcessorState
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected ca.uqac.lif.jerrydog.RequestCallback.Method m_method
      The HTTP method
      protected int m_port
      The TCP port on which the gateway listens for requests
      protected java.lang.String m_pullUrl
      The URL to call when this processor is asked for a new event.
      protected boolean m_pushOnReceive
      Whether this processor makes a call to push() when a request is received
      protected java.util.concurrent.locks.Lock m_queueLock
      A lock to access the queue
      protected java.util.Queue<java.lang.String> m_receivedStrings
      A queue of character strings received over the network
      protected ca.uqac.lif.jerrydog.Server m_server
      An internal instance of HTTP server
      protected java.lang.String m_url
      The URL on which the gateway listens for requests
      • Fields inherited from class ca.uqac.lif.cep.SynchronousProcessor

        m_inputPushables, m_outputPullables, m_tempQueue
      • Fields inherited from class ca.uqac.lif.cep.Processor

        m_context, m_eventTracker, m_hasBeenNotifiedOfEndOfTrace, m_inputArity, m_inputCount, m_inputPullables, m_inputQueues, m_notifiedEndOfTraceDownstream, m_outputArity, m_outputCount, m_outputPushables, m_outputQueues, MAX_PULL_RETRIES, s_versionString
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpDownstreamGateway​(int port, java.lang.String url, ca.uqac.lif.jerrydog.RequestCallback.Method m)
      Creates a new downstream gateway.
      HttpDownstreamGateway​(int port, java.lang.String url, ca.uqac.lif.jerrydog.RequestCallback.Method m, java.lang.String pull_url)
      Creates a new downstream gateway.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean compute​(java.lang.Object[] inputs, java.util.Queue<java.lang.Object[]> outputs)  
      HttpDownstreamGateway duplicate​(boolean with_state)  
      HttpDownstreamGateway setPushOnReceive​(boolean b)  
      void start()  
      void stop()  
      • Methods inherited from class ca.uqac.lif.cep.tmf.Source

        push
      • Methods inherited from class ca.uqac.lif.cep.SynchronousProcessor

        getPullableOutput, getPushableInput, setEventTracker
      • Methods inherited from class ca.uqac.lif.cep.Processor

        allNotifiedEndOfTrace, allNull, associateTo, associateToInput, associateToOutput, copyInputQueue, copyOutputQueue, duplicate, duplicateInto, equals, getAt, getContext, getContext, getEmptyQueue, getEventTracker, getId, getInputArity, getInputCount, getInputQueue, getInputType, getInputTypesFor, getLeaves, getLeaves, getOutputArity, getOutputCount, getOutputQueue, getOutputType, getPullableInput, getPullableOutput, getPushableInput, getPushableOutput, hashCode, leftShift, newContext, onEndOfTrace, or, or, print, printState, read, readState, reset, rightShift, setContext, setContext, setPullableInput, setPushableOutput, startAll, stopAll
      • Methods inherited from class java.lang.Object

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

      • m_receivedStrings

        protected java.util.Queue<java.lang.String> m_receivedStrings
        A queue of character strings received over the network
      • m_queueLock

        protected java.util.concurrent.locks.Lock m_queueLock
        A lock to access the queue
      • m_port

        protected int m_port
        The TCP port on which the gateway listens for requests
      • m_server

        protected ca.uqac.lif.jerrydog.Server m_server
        An internal instance of HTTP server
      • m_url

        protected java.lang.String m_url
        The URL on which the gateway listens for requests
      • m_method

        protected ca.uqac.lif.jerrydog.RequestCallback.Method m_method
        The HTTP method
      • m_pushOnReceive

        protected boolean m_pushOnReceive
        Whether this processor makes a call to push() when a request is received
      • m_pullUrl

        protected java.lang.String m_pullUrl
        The URL to call when this processor is asked for a new event. This can be null; in such a case, the processor won't do anything when being pulled.
    • Constructor Detail

      • HttpDownstreamGateway

        public HttpDownstreamGateway​(int port,
                                     java.lang.String url,
                                     ca.uqac.lif.jerrydog.RequestCallback.Method m)
        Creates a new downstream gateway.
        Parameters:
        port - The TCP port to listen to
        url - The URL to respond to
        m - The HTTP method (GET, POST, etc.) to respond to
      • HttpDownstreamGateway

        public HttpDownstreamGateway​(int port,
                                     java.lang.String url,
                                     ca.uqac.lif.jerrydog.RequestCallback.Method m,
                                     java.lang.String pull_url)
        Creates a new downstream gateway.
        Parameters:
        port - The TCP port to listen to
        url - The URL to respond to
        m - The HTTP method (GET, POST, etc.) to respond to
        pull_url - The URL to call when this processor is asked for a new event. This can be null; in such a case, the processor won't do anything when being pulled.
    • Method Detail

      • start

        public void start()
                   throws ca.uqac.lif.cep.ProcessorException
        Overrides:
        start in class ca.uqac.lif.cep.Processor
        Throws:
        ca.uqac.lif.cep.ProcessorException
      • stop

        public void stop()
                  throws ca.uqac.lif.cep.ProcessorException
        Overrides:
        stop in class ca.uqac.lif.cep.Processor
        Throws:
        ca.uqac.lif.cep.ProcessorException
      • compute

        protected boolean compute​(java.lang.Object[] inputs,
                                  java.util.Queue<java.lang.Object[]> outputs)
                           throws ca.uqac.lif.cep.ProcessorException
        Specified by:
        compute in class ca.uqac.lif.cep.SynchronousProcessor
        Throws:
        ca.uqac.lif.cep.ProcessorException
      • duplicate

        public HttpDownstreamGateway duplicate​(boolean with_state)
        Specified by:
        duplicate in interface ca.uqac.lif.cep.Duplicable
        Specified by:
        duplicate in class ca.uqac.lif.cep.Processor