Java Operator 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 we 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.

Importing This Sample into StreamBase Studio

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

  • From the top menu, click FileLoad StreamBase Sample.

  • Select this sample from the Extending StreamBase list.

  • Click OK.

StreamBase Studio creates a project for the sample.

Sample Location

By default, the sample files are installed in:

  • On Windows: C:\Program Files\StreamBase Systems\StreamBase.n.m\sample\javaoperator

  • On UNIX: /opt/streambase/sample/javaoperator

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace. StreamBase Systems recommends that you use the workspace copy of the sample, especially on UNIX, where you may not have write access to /opt/streambase. In the default installation, the path to this sample in your Studio workspace is:

UNIX:       
  ~/streambase-studio-n.m-workspace/sample_javaoperator
Windows XP:
  C:\Documents and Settings\username\My Documents\StreamBase Studio n.m Workspace\
      sample_javaoperator
Windows Vista:
  C:\Users\username\Documents\StreamBase Studio n.m Workspace\
      sample_javaoperator

Running the Java Operator Sample in StreamBase Studio

  1. In the Package Explorer, notice that the StringCase.jar file is imported into the javaoperator project. This JAR file contains the StringCase.class, which extends com.streambase.sb.operator.Operator.

  2. Double-click the StringCase.sbapp application to open it in the EventFlow Editor.

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

  4. Select the StringCase.sbapp tab in the EventFlow Editor, then click the Run button. The application starts and Studio switches to the SB Test/Debug perspective.

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

  6. In the symbol field, enter ibm, and in the price field, enter 120, and click Send Data.

  7. In the Application Output View, notice that in OutputStream1, after the write to the Query Table, the symbol string is IBM in uppercase.

  8. Type symbol Dell, price 40, and click Send Data.

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

  10. Type symbol ibm, and click Send Data. The price, 120, is displayed in the Application Output window.

  11. Type symbol dElL in mixed case, and click Send Data. The price, 40, is displayed in the Application Output window. Notice that the table lookup was successful, because we had stored the string as uppercase, despite the mixed-case initial input.

  12. When done, press F9 or click the Stop Running Application button.