- Index

< Previous |  | Next >

# 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/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.

## Importing This Sample into StreamBase Studio

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

- From the top-level menu, select File → Load StreamBase Sample.

- Enter `custom` to narrow the list of options.

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

- Click OK.

StreamBase Studio creates a single project for the sample.

## Running This Sample in StreamBase Studio

1. 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 Maven → Update Project from the context menu.

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

3. Open the `customadapter.sbapp` file and click the Run button. This opens the SB Test/Debug perspective and starts the module. The `InputExample` adapter in the application automatically begins reading from an input file.

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

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

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

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