Contents
This sample uses an Extension Point operator to dispatch tuples to one of two submodules, based on a user-specified action at runtime. The submodules simply double or triple an integer field within the incoming tuple. If no action is specified, the tuple is sent to both modules.
This sample illustrates StreamBase interfaces used with the Extension Point operator, and illustrates the dispatch of tuples to one of two modules based on an expression that evaluates to the identifier of one of the modules. This sample also illustrates the use of a PNG image file to provide the Extension Point operator with a custom icon.
This sample illustrates several aspects of Extension Point operators and StreamBase interfaces. For further exploration of StreamBase interfaces, see the Interfaces Sample.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, click
> . -
Enter
sample group
to narrow the list of options. -
Select Operator sample group from the Data Constructs and Operators category.
-
Click
.
StreamBase Studio creates a single project for the operator samples.
-
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/com.tibco.sb.sample.operator
folder. -
Open the
ExtensionPoint.sbapp
file and click the Run button. This opens the SB Test/Debug perspective and starts the module. -
In the Output Streams view, select the
Output
output stream. No output is displayed at this point. -
In the Manual Input view, select the
Input
input stream -
Enter the following field values:
Field Enter this value value 2 action double -
Click Send Data, and a tuple arrives in the Output Streams view. Select the new tuple and observe this data below the output stream table:
value=2, action=double, newValue=4, path=[Entering port 1 for Name dispatch,Doubler.sbapp]
-
In the Manual Input view, enter the following field values:
Field Enter this value value 2 action triple -
Click Send Data, and a tuple arrives in the Output Streams view. Select the new tuple and observe this data below the output stream table:
value=2, action=triple, newValue=6, path=[Entering port 1 for Name dispatch,Tripler.sbapp]
-
In the Manual Input view, enter the following field values:
Field Enter this value value 3 action null -
Click Send Data, and two tuples arrive in the Output Streams view. Select the new tuples and observe this data below the output stream table:
value=3, action=null, newValue=6, path=[Entering port 2 for Broadcast dispatch,Doubler.sbapp] value=3, action=null, newValue=9, path=[Entering port 2 for Broadcast dispatch,Tripler.sbapp]
-
When done, press F9 or click the Terminate EventFlow Fragment button.
The Extension Point sample is composed of following files:
- ExtensionPoint.sbapp
-
The top-level application for this sample. Its input stream accepts an integer value and a string field,
action
, that determines what to do with the integer. The recognized values foraction
aredouble
,triple
, andnull
.
The following file is located in the same package folder as the sample operator's application files.
- Multiplier.sbint
-
A StreamBase interface that defines two input streams and one output stream, and defines named schemas used by those streams.
The following files are located in the com.tibco.sb.sample.operator.modules
package folder of the sample
operator's src/main/eventflow/
project directory.
packageName
- Doubler.sbapp
-
A module that implements the streams and schemas defined in the
Multiplier.sbint
interface. This module doubles its input value, and appends as a list(string) the StreamBase path through this module. - Tripler.sbapp
-
Another module that implements the
Multiplier.sbint
interface. This module performs the same actions asDoubler.sbapp
except that it triples its input value.
Open ExtensionPoint.sbapp
in Studio and look at the
Properties view for the Extension Point operator named Multiply
. The Concurrency tab is entirely responsible for directing
input tuples to one or both of the referenced modules, either Doubler.sbapp
or Tripler.sbapp
:
-
If a tuple enters input port 2, the dispatch style is Broadcast, which means the tuple is sent to both modules.
-
If a tuple enters input port 1, the dispatch style is Name. In this case, the expression
lower(action)
must resolve to the identifier of one of the two modules (double
ortriple
) as defined in the Modules tab.
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_operator
See Default Installation
Directories for the default location of studio-workspace
on your system.