Contents
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.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click → .
-
Select this sample from the Embedded Adapters list.
-
Click OK.
StreamBase Studio creates a single project for the sample.
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/
-
In the Package Explorer, double-click to open the
customadapter.sbappapplication. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
Run StreamBase Application (Default Launch) button.
(Not the Run button.) This opens the
Test/Debug perspective and starts the application.
-
The adapter Properties view Server Diagnostics tab will display some debugging information about what files are being opened.
-
The Application Output pane will display lines as they are read from the file.
-
Click → (F9)
-
Open
out.txtin any text editor to see the lines written back to the file system by the output adapter.
-
Change the current working directory to where the sample is installed.
-
Run
sbd -f sbd.sbconf customadapter.sbapp -
In another window, run
sbc dequeue OutputStreamto see the lines being read. -
Run
sbadmin shutdown. -
Open
out.txtin any text editor to see the lines written back to the file system by the output adapter.
