Contents
The ComplexTypeRunner.sbapp
sample demonstrates how to use
the StreamBase Client API to retrieve fields and values from complicated structures
from a tuple, such as a list of integers or a list of tuples that contain a double.
The following files are included in the sample's project:
-
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 theComplexTypeAccessor
Custom Java Operator to emit the summed integer/double values as described above. -
sbd.sbconf
: A StreamBase Server configuration file containing a reference to thejava-bin
directory containing theComplexTypeAccessor
Java class.
For details about how we used the API to extend com.streambase.sb.operator.*
, see Using the StreamBase Java
Operator Wizard in the API Guide. For information about
importing a JAR that contains a Java Operator in StreamBase Studio, and then selecting
an Operator
class from that JAR, see Using Java Operators in the
Authoring 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.
-
In the Package Explorer view, right-click on
ComplexTypeRunner.sbapp
, and select → . This opens the SB Test/Debug perspective and starts the application. -
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 have been entered, click . -
In the Application Output view, note the summed values:
intListSum = 3 tupleListSum = 3.0
-
When done, press F9 or click the button.
-
Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to your workspace copy of the sample.
-
In Window 1, start the application using the command:
sbd -f sbd.sbconf ComplexTypeRunner.sbapp
-
In Window 2, run the following command to dequeue tuples from the application's Output Stream:
sbc dequeue OutputStream
-
In Window 3, run the following command to enqueue tuples to the application's Input Stream:
sbc enqueue InputStream
Now enter the following field values:
null,null,"[1,2]","[""null,1.0"",""null,2.0""]"
-
In Window 2, observe the resulting output values for 'intListSum' and 'tupleListSum':
3,3
-
In Window 2, type: Ctrl+C to exit the
sbc
dequeue session. -
Again in Window 2, type the following command to terminate the sbd server instance:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
Select
Java Operator Complex Types
from the Extending StreamBase category. -
Click OK.
StreamBase Studio creates a project for the sample.
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 the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:
studio-workspace
/sample_javaoperator-complex-types
See Default Installation
Directories for the location of studio-workspace
on your system.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
streambase-install-dir
/sample/javaoperator-complex-types/
See Default Installation
Directories for the location of streambase-install-dir
on your system. This location
may require administrator privileges for write access, depending on your platform.