Contents
This sample demonstrates how a custom Java operator or embedded adapter can access alternative values for properties from
a StreamBase configuration file, typically sbd.sbconf, This capability lets instances of such components within an application access the same set of property values and override
a default value. For example, each adapter or Java operator instance can select from several pre-configured data sources or
connection strings.
The sample application has a Java operator containing a choice menu in its Operator Properties tab. The menu chooses one of
two strings. The strings are selectors for <choice> blocks in the provided sbd.sbconf file. The operator's typecheck method determines if the selector is valid and, if it is, retrieves the indicated property
from the configuration file.
When the sample application runs, the custom operator replaces the content of the first schema field, offset, of type String,
with text the menu setting causes it to retrieve from the configuration file. The string will either be "0" or "1". The downstream Map operator casts offset to integer and subtracts it from the id value that the Sequence operator inserted
in the schema in output field answer.
See the source sample's code for ConfigBasedOperatorSample.java and ConfigBasedOperatorSampleBeanInfo.java and the sbd.sbconf configuration file to learn more about the implementation. In the source file, the string configElement holds the property value retrieved from an XML node (<text> whose ID matches the choice string the user has selected.
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, double-click to open the
sample_javaoperator-confaccess.sbappapplication. Make sure the application is the currently active tab in the EventFlow Editor. -
Select the Java operator, open its Operator Properties tab, and observe that the drop-down menu is set to select .
-
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
Click and observe:
-
The sequence operator adds int
idto the tuple and sets it to 1 -
The GetOffset Java operator retrieves the value for
offsetspecified forchoice-1insbd.sbconf -
The Decrement Map operator casts
offsetfrom string to int and subtracts it fromidto populate the added field answer.
-
-
The Application Output view displays the content of the output stream, {string offset, int id, int answer} with content
offset=0,id=1,answer=1. -
Each time you click , the id and answer fields increment but the offset field does not change.
-
Press F9 or click the
Stop Running Application button and return to the SB Authoring view.
-
In the Java operator's Operator Properties tab, set the drop-down to . This changes the value retrieved from
sbd.sbconffrom 0 to 1. -
Repeat steps 3 - 6 and observe the Application Output view again. It displays the content of the output stream, {string offset, int id, int answer}, with content offset=1, id=1, answer=0.
-
Press F9 or click the
Stop Running Application button when you are finished running the application.
For details on retrieving properties from configuration files, see <adapter-configurations> documentation.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select → .
-
Type
javaopto narrow the list of options. -
Select javaoperator-confaccess from the Extending StreamBase category.
-
Click OK.
StreamBase Studio creates a single 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 permission problems. The default workspace location for this sample is:
studio-workspace/sample_javaoperator-confaccessSee 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-confaccessSee Default Installation Directories for the default location of studio-workspace on your system.
