Custom Java Operator Sample

About This Sample

The StringCase.sbapp sample application uses a Java operator to change the case of strings. This is then used to implement case-insensitive query table lookups.

This topic describes the Java operator sample, which includes a StreamBase application and a Java class that extends com.streambase.sb.streambase.operator.*.

For details about how StreamBase used the API to extend com.streambase.sb.operator.*, see Using the StreamBase Java Operator Wizard in the API Guide. For information about importing a JAR that contains a Java Operator in StreamBase Studio, and then selecting an Operator class from that JAR, see Using Java Operators in the Authoring Guide.

For details about using custom icons with your Java operators, see the Java Client library documentation for getIconResource in com.streambase.sb.operator.Operator

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, or use javac on the command line.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, select File>Import Samples and Community Content.

  • Enter javao to narrow the list of options.

  • Select Custom Java operator from the Extending StreamBase category.

  • Click Import Now.

StreamBase Studio creates a project for the sample.

Running This Sample in StreamBase Studio

  1. 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 Maven>Update Project from the context menu.

  2. Notice the src/main/java folder in the project folder. Under the packageName folder is StringCase.java, which extends com.streambase.sb.operator.Operator.

  3. Open the src/main/eventflow/packageName folder.

  4. Open the StringCase.sbapp EventFlow module file.

  5. Double-click the Java1 operator in the canvas to open its Properties view. In the Parameters tab, notice that the string conversion type is set by default to Lowercase. Change this setting to Uppercase. Do the same for the Java2 operator.

  6. Make sure StringCase.sbapp is the currently active tab in the EventFlow Editor, then click the Run button. This starts the fragment and Studio switches to the SB Test/Debug perspective.

  7. Select the Manual Input view. Select InputPrice from the Input Stream list.

  8. In the symbol field, enter ibm, and in the price field, enter 150, and click Send Data.

  9. In the Output Streams view, notice that in OutputStream1, after the write to the Query Table, the symbol string is IBM in uppercase.

  10. Type symbol Orcl, price 48, and click Send Data.

  11. In the Manual Input view, select PriceQuery from the Input Stream list.

  12. Type symbol ibm, and click Send Data. The price, 150, is displayed in the Output Streams view.

  13. Type symbol oRcL in mixed case, and click Send Data. The price, 48, is displayed in the Output Streams view. Notice that the table lookup was successful, because the string is stored as uppercase, despite the mixed-case initial input.

  14. When done, press F9 or click the Terminate EventFlow Fragment button.

Sample Location

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

See Default Installation Directories for the default location of studio-workspace on your system.