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
The source code for
src/main/java/ is included in
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.
In StreamBase Studio, import this sample with the following steps:
From the top-level menu, select> .
custom adapterto narrow the list of options.
Select Custom Java embedded adapter from the Extending StreamBase category.
StreamBase Studio creates a single project for the sample.
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
Rebuild projectmessages finish before you proceed.
Double-click to open the
customadapter.sbappmodule. Make sure the module is the currently active tab in the EventFlow Editor.
Click the Run button. This opens the SB Test/Debug perspective and starts the module.
Wait for the Waiting for fragment to initialize message to clear. The
InputExampleadapter in the application automatically begins reading from an input file.
The Output Streams view displays lines as they are read from the file.
Press F9 or click the Terminate EventFlow Fragment button.
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.txtin the node directory:
out.txtto 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.
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.
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:
See Default Installation
Directories for the default location of
studio-workspace on your system.