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 Custom_Adapter_README.txt 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.

The source code for src/main/java/packagName/InputExample.java, src/main/java/packageName/InputExampleBeanInfo.java, and src/main/java/packageName/OutputExample.java is included in this sample.

Note

The Java code in this sample is delivered only in source code form. To build the code, you must load the sample into StreamBase Studio, which automatically builds the Java code.

Importing This Sample into StreamBase Studio

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

  • From the top-level menu, select File>Import Samples and Community Content.

  • Enter custom adapter to narrow the list of options.

  • Select Custom Java embedded adapter from the Extending StreamBase category.

  • Click Import Now.

StreamBase Studio creates a single project for the sample.

Running This Sample in StreamBase Studio

  1. In the Project Explorer view, open this sample's folder.

    Keep an eye on the bottom right status bar of the Studio window. Make sure any Updating, Downloading, Building, or Rebuild project messages finish before you proceed.

  2. Open the src/main/eventflow/packageName folder.

  3. Double-click to open the customadapter.sbapp module. Make sure the module is the currently active tab in the EventFlow Editor.

  4. Click the Run button. This opens the SB Test/Debug perspective and starts the module.

  5. Wait for the Waiting for fragment to initialize message to clear. The InputExample adapter in the application automatically begins reading from an input file.

  6. The Output Streams view displays lines as they are read from the file.

  7. Press F9 or click the Terminate EventFlow Fragment button.

  8. In the Project Explorer view, select this sample's project folder and press F5 to refresh the folder. You should now see the newly created file out.txt in the node directory: <workspace>/.nodes/<nodeName>/out.txt.

  9. Double-click out.txt to see the lines written back to the file system by the output adapter. By default, the file contains a copy of the text version of the topic page you are reading.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_custom-adapter

See Default Installation Directories for the default location of studio-workspace on your system.