Show TOC

Building a Custom Transporter ModuleLocate this document in the navigation structure

Use the ESP adapter toolkit to build a custom transporter module to use within the adapter instance of your choice.

Prerequisites

(Optional) See the $STREAMING_HOME/adapters/framework/examples/src directory for source code for sample transporters.

Procedure

  1. Create a class that extends the com.sybase.esp.adapter.framework.module.Transporter Java class that is included with the adapter toolkit.
  2. Implement the init() function.
    Prepare your input or output transporter module for the actions it is responsible for performing. For example, create a database connection or obtain properties from the adapter configuration file.
  3. Implement the start() function.
    Perform any necessary tasks when the adapter is started.
  4. Implement the execute() function.

    When the adapter framework calls this method, it is expected to run continuously until the adapter is requested to stop or until the adapter completes its work. Therefore, the code excerpt below might be found within a loop, or inside a callback method invoked by the transport when an event occurs, or inside a listener monitoring transport events.

    AepRecord is a single record or row in ESP format and has an operation code that can be set. Its default operation code is INSERT. Change this based on your needs. AdapterRow represents records as they flow from one module to the next. You can add multiple records as objects within a List of a single AdapterRow object. The AdapterRow has a timestamp, and block flags that control how its records are communicated to and from Event Stream Processor. See Event Blocks in the SAP Event Stream Processor: CCL Reference for additional details.

    The actions performed by this function depend on whether the transporter is input (datasource) or output (data sink). For example, for an input transporter that gets data from “myDataSource”, the execute() function might look like this:
    public void execute() throws Exception  {
    	String value = myDataSource.getNextValue();
    
    	AepRecord record = new AepRecord();
    	record.getValues().add(value);
    AdapterRow row = utility.createRow(record);
    utility.sendRow(row);
    }
    For an output transporter that sends data to “myDataSink”, the execute() function might look like this:
    public void execute() throws Exception  {
    	
    AdapterRow row = utility.getRow();
    if(row != null)
    {
    AepRecord record = (AepRecord)row.getData(0);
    if(record != null) {
    	String value = record.getValues().toString();
    	myDataSink.send(value);
    }
    }

    The difference between input and output transporters is that input transporters call utility.sendRow() to send data to a formatter or ESP publisher, while output transporters call utility.getRow() to obtain data from a formatter or ESP subscriber.

    For transporters that operate in streaming mode, call utility.sendRowsBuffer() (input) and utility.getRowsBuffer() (output).

    See the $STREAMING_HOME/adapters/framework/examples/src directory for source code for sample transporters.

  5. Implement the stop() function.
    Perform any necessary tasks when the adapter is stopped.
  6. Implement the destroy() function.
    Perform any cleanup tasks for your input or output transporter.
  7. (Optional) Call one of the following functions within the functions listed in the steps above:
    • Call utility.getParameters() to get parameters that are defined in the adapter configuration file.
    • Call utility.sendRow() to send data to the next module that is defined in the adapter configuration file.
    • Call utility.getRow() to obtain data from the previous module that is defined in the adapter configuration file.
    • Call utility.isStopRequested() to determine whether a stop command has been issued.
  8. Register the implemented Java class to $STREAMING_HOME/adapters/framework/config/modulesdefine.xml. For example:
    <TransporterDefn>
          <Name>MyOutputTransporter</Name>
          <Class>com.my.MyOutputTransporter</Class>
          <InputData>String</InputData>
        </TransporterDefn>
  9. Add the schema definitions for any unique parameters of the newly created module to the $STREAMING_HOME/adapters/framework/config/parametersdefine.xsd file.
    If any of the parameters for the newly created module are the same as parameters for the standard transporter modules, you do not need to add schema definitions for these parameters.
  10. Copy the .jar file containing the Java class you previously implemented and any other .jar files used by the custom adapter to $STREAMING_HOME/adapters/framework/libj.
  11. (Optional) Start the adapter instance by issuing:

    $STREAMING_HOME/adapters/framework/bin/start.bat <config file> or $STREAMING_HOME/adapters/framework/bin/start.sh <config file>

    where <config file> is the adapter configuration file in which you specified the adapter instance using the newly created transporter module.

  12. (Optional) Stop the adapter instance by issuing:

    $STREAMING_HOME/adapters/framework/bin/stop.bat <config file> or $STREAMING_HOME/adapters/framework/bin/stop.sh <config file>

    where <config file> is the adapter configuration file in which you specified the adapter instance using the newly created transporter module.

Example

Refer to $STREAMING_HOME/adapters/framework/examples for additional details and transporter examples, as well as $STREAMING_HOME/adapters/framework/examples/src for the source code for these examples.

Next Steps

Create an adapter configuration (.xml) file to define which adapter instance uses this newly created transporter module.