This topic explains how to use the StreamBase Java Operator wizard to generate the base code for a custom Java operator. For additional details, 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 library is not on your project's build path, it displays a message informing you of the problem. See Adding StreamBase Client Library to the Project Build Path.
For example:
|
When you are ready, click Next to proceed to the next page.
The wizard's second page is labeled Java Operator. Use the second page of the wizard to specify features you want generated as Java code, and to specify properties that can be configured in the generated operator at runtime.
An operator property is a Java property for this operator. For each property you specify, the wizard generates stub code that places a control in the Operator Properties tab of the Properties view for your operator. After you add implementation code to the generated stub code, the end-user of your operator can use these controls to modify the operation of your operator.
Edit the following fields in the wizard's Java Operator page:
- Operator Properties
-
Specify one or more properties that can be set or modified by users of your operator to control its operation. For each property you specify, the wizard generates code to place a control in the Operator Properties tab of the Properties view for your operator's icon. The Operator Properties grid is used in the same way as the Adapter Properties grid in the New Adapter wizard. See Adding Adapter Properties for instructions on using the Operator Properties grid.
- Method stubs to create
-
The wizard generates stub code for the following methods in the class that implements your adapter:
- init()
-
When enabled, this option generates stub code for an
init()method that runs when the adapter is started by its hosting StreamBase Server.Default state for input adapters: enabled and the control dimmed. (That is, the wizard always generates an
init()method for input adapters and you cannot specify otherwise.)Default state for output adapters: enabled.
- shutdown()
-
When enabled, this option generates stub code for a
shutdown()method that allows this adapter to provide processing steps such as closing logs and files when the hosting StreamBase Server begins to shut down.Default state for both input and output adapters: enabled.
- Methods to control enablement of UI widgets
-
When enabled, this option generates stub code for each property you added in the Operator Properties section, that allows each property to be enabled or disabled depending on conditions you specify in code. Disabled properties are dimmed in the Operator Properties tab of the Properties view for your operator's icon. You might use this feature in a set of related properties, to enable one property only if another property in the group is enabled.
For example, in a set of two properties, one property might provide a check box in which the operator's user specifies whether or not to filter a stream, while the second property provides a text box in which the user specifies the string to filter against. In this case, you can enable the text box property only if the check box property is enabled first.
Default state: enabled. This control is dimmed until you have added at least one property in the Operator Properties section of this dialog page.
After completing the second page of the New StreamBase Operator wizard, complete the process with these steps:
-
When you are done adding properties on the second page, click .
The wizard generates two Java files: one containing an operator class, the other, a beaninfo class. You will probably not need to edit the beaninfo class file. However, you must provide implementation code for all places marked
// TODOin the generated operator class file.The class generated for the operator extends
com.streambase.sb.operator.Operator. Operators must callsendOutput(to provide tuples to the application.int,Tuple) -
Click to complete the wizard.
-
The wizard generates Java code for your operator, opens the primary class file for editing, then prompts you to refresh the project's typecheck environment. The first time you run the wizard, it automatically refreshes the typecheck environment so that the new operator's icon appears right away in the Palette view.
Tip
You must refresh the typecheck environment again every time you make changes to the operator's Java code. Do this by pressing Ctrl+F5 (or by right-clicking the project's name in the Package Explorer and selecting → from the context menu).
-
An icon for your new operator now appears in in the Project Operators section of the Insert Java Operator dialog. Invoke this dialog by dragging the Java Operator icon from the Operators and Adapters drawer of the Palette view to the canvas. Add an instance of your operator to the canvas by selecting your operator's icon in the dialog and clicking .
-
For details about using the StreamBase API for Java operators, start in Creating Custom Java Operators in the StreamBase API Guide.
-
For the Java Client library 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.
