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 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/InputExample.java
, src/main/java/InputExampleBeanInfo.java
, src/main/java/OutputExample.java, and src/main/java/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.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
> . -
Enter
custom
to narrow the list of options. -
Select Custom Java embedded adapter from the Extending StreamBase category.
-
Click
.
StreamBase Studio creates a single project for the sample.
-
In the Project Explorer view, open the sample you just loaded.
If you see red marks on a project folder, wait a moment for the project to load its features.
If the red marks do not resolve themselves after a minute, select the project, right-click, and select
> from the context menu. -
Open the
src/main/eventflow/
folder.packageName
-
Open the
customadapter.sbapp
file and click the Run button. This opens the SB Test/Debug perspective and starts the module. TheInputExample
adapter 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.txt
in the project folder. -
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.
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.