Class GenericGateway

java.lang.Object
coldfusion.eventgateway.GenericGateway
All Implemented Interfaces:
Gateway

public abstract class GenericGateway extends Object implements Gateway
An abstract class that implements some of the ColdFusion event gateway protocol. It uses the Template Method pattern to handle the actual start / stop actions on the concrete gateway.

You can derive from this class, and it will take care of the basic mechanics of implementing a gateway. Your class must implement at least the following gateway operations: startGateway(), stopGateway(), and outgoingMessage().

See Also:
  • Field Details

    • status

      protected int status
    • listeners

      protected String[] listeners
  • Constructor Details

    • GenericGateway

      public GenericGateway(String gatewayID)
      Constructor.

      If your gateway defines its own constructor (to process a configuration file, for example), include a call to this constructor in your gateway constructor:
      super(gatewayID).

      Parameters:
      gatewayID - The gateway ID string, provided by the ColdFusion MX Administrator.
  • Method Details

    • getGatewayID

      public String getGatewayID()
      Return the ID that uniquely defines the gateway instance.

      This function does not typically need to be overridden.

      Specified by:
      getGatewayID in interface Gateway
      Returns:
      The gateway ID set by setGatewayID()
    • setGatewayID

      public void setGatewayID(String id)
      Set the ID that uniquely defines the gateway instance.

      This function does not typically need to be overridden.

      Specified by:
      setGatewayID in interface Gateway
      Parameters:
      id - Gateway ID string
      See Also:
    • setCFCListeners

      public void setCFCListeners(String[] listeners)
      Set the CFClisteners list.

      This function does not typically need to be overridden.

      Specified by:
      setCFCListeners in interface Gateway
      Parameters:
      listeners - A list of file system paths to ColdFusion components that listen for event messages from this gateway.
      See Also:
    • getHelper

      public GatewayHelper getHelper()
      Override this function if you want to provide a helper class for your gateway.

      Return a CFC helper class (if any) so that a CFC can invoke gateway-specific utility functions that might be useful to the CFML developer. The helper class must implement the GatewayHelper marker interface.

      Called by the CFML function getGatewayHelper(gatewayID).

      Specified by:
      getHelper in interface Gateway
      Returns:
      null - No helper is defined by default.
      See Also:
    • getStatus

      public int getStatus()
      Return the status of the gateway.

      This function might need to be overridden if the resource can change status asynchronously from the gateway.

      Specified by:
      getStatus in interface Gateway
      Returns:
      one of STARTING, RUNNING, STOPPING, STOPPED, FAILED.
    • start

      public void start()
      Start the gateway.

      This implementation handles the mantenance of the gateway status only. It calls startGateway which is where you should implement your gateway-specific starting code.

      Any exceptions thrown from startGateway() will be logged in the eventgateway.log file.

      Specified by:
      start in interface Gateway
      See Also:
    • stop

      public void stop()
      Stop the gateway.

      This implementation handles the maintenance of the gateway status. It calls stopGateway, which is where you should implement your gateway-specific code.

      The method logs any exceptions thrown by stopGateway() in the eventgateway.log file.

      Specified by:
      stop in interface Gateway
      See Also:
    • restart

      public void restart()
      Restart this gateway.

      Implemented as a call to stop() and then start().

      You might override this to optimize processing, depending on the service the gateway communicates with.

      Specified by:
      restart in interface Gateway
      See Also:
    • startGateway

      protected abstract void startGateway() throws Exception
      Gateway startup method.

      You must implement this method with the startup code for your gateway.

      Throws:
      Exception
      See Also:
    • stopGateway

      protected abstract void stopGateway() throws Exception
      Gateway shutdown method.

      You must implement this method with the shutdown code for your gateway.

      Throws:
      Exception
      See Also:
    • sendMessage

      protected boolean sendMessage(CFEvent msg)
      Send an event to the ColdFusion event gateway service. This is a utility method for convenience.
      Parameters:
      msg - The event structure to pass to ColdFusion.
      Returns:
      true if the event was successfully placed on the queue.
    • getGatewayServices

      protected GatewayServices getGatewayServices()
      Provide access to the ColdFusion GatewayServices object.
      Returns:
      the GatewayServices object.
    • getListeners

      protected String[] getListeners()
      Return the listeners for this gateway.
      Returns:
      An array of paths for the gateway's listener CFCs.