Custom Embedded Adapter Sample

This sample demonstrates the implementation of a custom embedded input adapter and a custom embedded output adapter. The example input adapter reads lines from a configurable file at a configurable rate and outputs tuples with a single string field containing one line of the file at a time. The example output adapter simply writes the tuples it receives out to a configurable file, one tuple per line. The included StreamBase application simply connects the two adapters, reading from one file, and outputting the lines of that file to another file. (Note that this does not make an exact copy because the tuples are output in CSV format, and may require escaping.)

The default input adapter configuration is to read this file (Custom_Adapter_README.html) at one line per second (1000 milliseconds). The default output adapter configuration is to write these lines out to out.txt. These can be changed by importing the sample into your workspace (see below), clicking the desired adapter, and changing its parameters in the Properties view.

Because this sample uses custom, project-local adapters, sbd must be told about the adapter JARs via a custom sbd.sbconf, which is included in the sample. This is not needed when run from StreamBase Studio because Studio automatically imports JARs present in the project.

The source code for InputAdapter.java, InputAdapterBeanInfo.java, and OutputAdapter.java is included in this sample, along with an Ant build file for building the adapter JARs. You can find a walk-through of these source files in Using the Embedded Adapter API in the StreamBase documentation.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, click FileLoad StreamBase Sample.

  • Select this sample from the Embedded Adapters list.

  • Click OK.

StreamBase Studio creates a single project for the sample.

Installed Sample File Locations

By default, the sample files are installed in:

On Windows

C:\Program Files\StreamBase Systems\StreamBase.n.m\sample\adapter\embedded\custom-adapter\

On UNIX

/opt/streambase/sample/adapter/embedded/custom-adapter/

Running This Sample in StreamBase Studio

  1. In the Package Explorer, double-click to open the customadapter.sbapp application. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run StreamBase Application (Default Launch) button. (Not the Run button.) This opens the Test/Debug perspective and starts the application.

  3. The adapter Properties view Server Diagnostics tab will display some debugging information about what files are being opened.

  4. The Application Output pane will display lines as they are read from the file.

  5. Click RunStop Running Application (F9)

  6. Open out.txt in any text editor to see the lines written back to the file system by the output adapter.

Running This Sample in Terminal Windows

  1. Change the current working directory to where the sample is installed.

  2. Run sbd -f sbd.sbconf customadapter.sbapp

  3. In another window, run sbc dequeue OutputStream to see the lines being read.

  4. Run sbadmin shutdown.

  5. Open out.txt in any text editor to see the lines written back to the file system by the output adapter.