Custom Java Operator Complex Types Sample

About This Sample

This sample demonstrates how to use the StreamBase Client API to retrieve fields and values from complex structures in a tuple, such as a list of integers or a list of tuples that contain a double.

For details about how StreamBase used the API to extend com.streambase.sb.operator.*, see Using the Java Operator API in the API Guide.

For details about using custom icons with your Java operators, see the Java Client library documentation for getIconResource in com.streambase.sb.operator.Operator

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, or use javac on the command line.

Importing This Sample into StreamBase Studio

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

  • From the top-level menu, select File>Import Samples and Community Content.

  • Enter javao to narrow the list of options.

  • Select Custom Java operator that manipulates non-primitive from the Extending StreamBase category.

  • Click Import Now.

StreamBase Studio creates a 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 ComplexTypeRunner.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the fragment.

  4. In the Manual Input tab, add two intList elements and enter the values: intList[0] = 1 intList[1] = 2 Also add two tupleList elements and enter the values: tupleList[0] > innerDouble = 1.0 tupleList[1] > innerDouble = 2.0 Once all values are entered, click Send Data.

  5. In the Output Streams view, note the summed values:

    intListSum = 3 tupleListSum = 3.0
    
  6. When done, press F9 or click the Terminate EventFlow Fragment button.

This Sample's Files

The Java Operator Complex Types sample includes the following files:

ComplexTypeAccessor.java

The source code for a Customer Java Operator which takes in two complex fields, intList (a list of integers) and tupleList (a list of tuples, each of which has a double field, innerDouble). The operator emits two additional fields, intListSum (a sum of all integer values in the intList field) and tupleListSum (a sum of all innerDouble values from all tuples contained in the tupleList list).

ComplexTypeRunner.sbapp

A simple EventFlow application which uses the ComplexTypeAccessor Custom Java Operator to emit the summed integer and double values as described above.

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_javaoperator-complex-types

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