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 InputExample.java, InputExampleBeanInfo.java, OutputExample.java, and OutputExampleBeanInfo.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.

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 button. This opens the SB Test/Debug perspective and starts the application. The InputExample adapter in the application automatically begins reading from an input file.

  3. The Application Output view displays lines as they are read from the file.

  4. Press F9 or click the Stop Running Application button.

  5. In the Package Explorer, 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 project folder.

  6. 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.

Importing This Sample into StreamBase Studio

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

  • From the top menu, select FileLoad StreamBase Sample.

  • Select adapter\embedded\custom-adapter from the Extending StreamBase category.

  • Click OK.

StreamBase Studio creates a single project for the sample.

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 the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_custom-adapter

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

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/adapter/embedded/custom-adapter

See Default Installation Directories for the location of streambase-install-dir on your system. This location may require administrator privileges for write access, depending on your platform.