This topic describes how to add a custom Java operator to a StreamBase application.
Prerequisite steps (described in Developing Java Operators in the API Guide):
-
You have created one or more custom Java operators (for example, by using the StreamBase Java Operator wizard), and edited the generated Java source to add the functionality you want, or placed a JAR file containing one or more custom Java operators in your project.
-
The StreamBase Java Client API is on your project's build path.
-
You have refreshed the project's Typecheck Environment.
To add a Java operator to an EventFlow application:
-
Open the application to which you want to add the Java operator.
-
Open the Project Operators drawer of the Palette and find the Java operator you want to use. If you are using an operator whose files are stored outside the current project, make sure that its location is in the resource search path of the application (as described in StreamBase Project Properties).
-
Drag the Java operator icon from the Palette into your EventFlow Editor.
-
Connect the new Java operator instance into your application's flow, by drawing arcs from the operator ports to the appropriate components.
-
Open the Properties view for the operator and define its properties in the tabs, as described in the remainder of this topic.
To add a Java operator to a StreamSQL application:
-
Open the ssql application to which you want to add the Java operator.
-
Add a StreamSQL APPLY statement, as described in the StreamSQL Guide.
This simple example shows a Java operator used to convert strings to lowercase, and pass the result directly through on the output stream. Possibly, the ConversionType value could have been set to "Upper Case" instead.
CREATE INPUT STREAM InputPrice ( symbol string(10), price double ); CREATE OUTPUT STREAM OutputStream1; APPLY JAVA "StringCase" ( ConversionType = "Lower Case" ) FROM InputPrice INTO OutputStream1;
-
Save the application. When you are ready to test it, click the
button.
For details about using the APPLY JAVA statement, refer to the APPLY Statement topic in the StreamSQL Guide.
Name: Every application component must have a unique name. Use this field to specify or change the component's name. The name must contain only alphabetic characters, numbers, and underscores, and no hyphens or other special characters. The first character must be alphabetic or an underscore.
Enable Error Output Port: Check this box to add an Error Port to this component. In the EventFlow canvas, the Error Port shows as a red output port, always the last port for the component. See Using Error Ports and Error Streams to learn about Error Ports.
Description: Optionally, enter a description to briefly describe the component's purpose and function. In the EventFlow canvas, you can see the description by pressing Ctrl while the component's tooltip is displayed.
The Parameters tab displays the parameters that you or another developer implemented in the custom Java Operator class. For example, the Operator class may present a radio button choice for a Boolean field, a text box for a Double, a pull-down selector for an Int, a table for a String Array, and a text field for a String.
For example:
|
The contents and functionality of the Parameters tab are set entirely by your
implementation of the Java Operator class. For implementation details, see Using the Java Operator API in the
API Guide. Also refer to the com.streambase.sb.operator.* Javadoc for the StreamBase Java API. You
should also run the installed Java Operator sample, view the source for
StringCase.java, and see the sample's README in streambase_directory/sample/javaoperator/*.
- Run this component in a separate thread
-
This option causes the server to process the component's requests concurrently with other processing in the application. You can distribute the processing of the threads automatically across multiple processors on an SMP machine.
If this is a compute-intensive component and you know that it can run without data dependencies on other components in the StreamBase application, you may be able to improve performance by enabling this option.
Caution
These features are not suitable for every application. For details, see Execution Order, Concurrency, and Parallelism. It includes important guidelines for the use of these features.
- Run in parallel threads
-
If you checked the first option, you can also choose this option, which causes the server to run multiple instances of this component. That is, each instance runs in its own thread. At run time, tuples are dispatched to particular instances based on the Key Expression value (which must evaluate to an int).
To avoid hard-coding Java operator property values within StreamBase
applications, variables can be defined in the StreamBase configuration
file and referenced from Java operator properties. For example, the value for a
property can be entered as ${MyIntegerValue} if the
following element exists in the StreamBase configuration file:
<operator-parameters> <operator-parameter name="MyIntegerValue" value="123"/> </operator-parameters>
-
StreamBase Project Properties (to add a Java operator to your project's Java Build Path)
-
StreamSQL: APPLY Statement
