This topic explains how to use the StreamBase Java Operator wizard to generate the base code for a custom Java operator. For additional details, please refer to the StreamBase Help topics listed in Related Topics.
StreamBase provides a number of built-in operators, such as Filter,
Java, Map, Aggregate, and Union, to perform common processing on streaming data.
StreamBase also provides an operator API, com.streambase.sb.operator, which you can extend to
build custom functionality.
The Java Operator wizard helps you get started with the operator API by stepping you
through the definition process. The Java source file that it generates has commented
// TODO sections that you can later edit to add the
functionality you want.
After you replace these sections with your implementation code, you can use the operator immediately in your applications that you run locally in StreamBase Studio. If you are running your applications remotely, you may want to generate a JAR first.
To open the wizard, click → → . Edit these fields in the wizard:
- Source folder
-
The path to an existing folder within your project. By default, StreamBase projects contain a
java-srcsubfolder, which you can use. - Package
-
While you could use the default package, it is recommended that you specify a different one, such as com.example.mysbapps.operators.
- Name
-
A name for your class, such as
MyJavaOperator. - Display Name
-
The human readable name you want to show in the Palette view and in the blue text above instances of your operator in the EventFlow canvas.
- Number of Input Ports
-
Specify the number of input ports that the operator's UI will present to StreamBase Studio users. Of course, you can change this setting after the code is generated.
- Number of Output Ports
-
Specify the number of output ports that the operator's UI will present to StreamBase Studio users. Of course, you can change this setting after the code is generated.
If the wizard detects that the StreamBase Java Client API is not on your project's build path, it displays a message informing you of the problem. See Adding StreamBase Client API to the Project Build Path.
For example:
|
When you are ready, click Next to proceed to the next page.
Use the second page of the Java Operator wizard to set the properties that can be
configured in the created operator later, when you add it to a
StreamBase application (as described in Using
the Java Operator in the Authoring Guide). You can also, optionally, create
stubs for the init() or shutdown() methods.
-
Define properties for the operator:
-
Click the button.
-
In the New Operator Property dialog, set the
Property,Name,Displayname, anddefaultvalues. -
In the New Adapter Property dialog, set the
Property,Name,Displayname, andDefaultValue. By default, properties are required: uncheckOptional propertyif you want to make this property optional. -
Click to add the property to the Java Operator page.
-
Repeat the previous steps for each property you want to add.
Use the other buttons to modify or manage properties in the adapter. For example, select a property and click to change its values; use the and buttons to change the order of properties in the generated adapter.
-
-
Optionally, change the default setting to Use a background thread. When enabled, this option generates code that enqueues the tuples in a thread separate from the application’s main thread.
-
Optionally, change which method stubs will be created:
-
init()
-
shutdown()
-
-
When you are ready, click . The wizard generates and opens a Java source file for your Java Operator class, and a BeanInfo Java source file, which you can use to control which properties are exposed, if any.
-
The wizard prompts you to refresh the project's Typecheck Environment. Do this in one of the following ways:
-
Switch to the project's EventFlow application and press Ctrl-F5, or run Refresh Project Typecheck Environment from the context menu.
-
Select the project's name in the Package Explorer, right-click, and choose → .
Notice that refreshing the typecheck environment (Ctrl-F5) is not the same as the Apply and Typecheck operation (Ctrl-T).
The new operator does not appear in the Project Operators drawer of the Palette view until you run this step.
Tip
You must repeat this step whenever you make changes to source files for your Java operator.
-
For EventFlow applications, StreamBase Studio makes a new Java operator icon available in the Project Operators drawer of the Palette. You can drag the icon into the EventFlow editor and add it to your application.
-
For details about using the StreamBase API for Java operators, start in Using the Java Operator API in the StreamBase API Guide.
-
For the Java API Javadoc, see theAPI References topic of the StreamBase Reference Guide.
-
Using Java Operators in the Authoring Guide describes how to add your completed Java operator to an EventFlow application.
-
APPLY Statement describes how to add a Java operator to a StreamSQL application.
