Extension Point Operator Sample

About This Sample

This sample uses an Extension Point operator to dispatch tuples to one of two sub-modules, based on a user-specified action at runtime. The sub-modules simply double or triple an integer field within the incoming tuple. If no action is specified, the tuple is sent to both modules.

This sample illustrates StreamBase interfaces used with the Extension Point operator, and illustrates the dispatch of tuples to one of two modules based on an expression that evaluates to the identifier of one of the modules. This sample also illustrates the use of a PNG image file to provide the Extension Point operator with a custom icon.

There is a related sample that illustrates another aspect of Extension Point operators and StreamBase interfaces:

Sample Description
Interfaces Sample Demonstrates how to use StreamBase interfaces to enforce a set of stream and schema definitions, and to use different implementations of the same interface for different purposes.

Importing This Sample into StreamBase Studio

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

  • From the top menu, click FileLoad StreamBase Sample.

  • Type operator to narrow the list of options.

  • Select Operator sample group from the Data Constructs and Operators category.

  • Click OK.

StreamBase Studio creates a single project for the operator samples.

Running ExtensionPoint.sbapp in StreamBase Studio

  1. In the Project Explorer, open the sample you just loaded.

  2. Open the src/main/eventflow folder.

  3. Open the package folder (most samples contain a single package folder. Open the top-level package folder if your sample contains more than one folder).

  4. Open the ExtensionPoint.sbapp application and click the Run button. This opens the SB Test/Debug perspective and starts the application.

    If you see red marks, wait a moment for the project in Studio to load its features.

    If red marks do not resolve themselves in a moment, select the project and right-click MavenUpdate Project from the context menu.

  5. In the Application Output view, select the Output output stream. No output is displayed at this point.

  6. In the Manual Input view, select the Input input stream

  7. Enter the following field values:

    Field Enter this value
    value 2
    action double
  8. Click Send Data, and a tuple arrives in the Application Output view. Select the new tuple and observe this data below the output stream table:

    value=2, action=double, newValue=4, path=[Entering port 1 for Name dispatch,Doubler.sbapp]
  9. In the Manual Input view, enter the following field values:

    Field Enter this value
    value 2
    action triple
  10. Click Send Data, and a tuple arrives in the Application Output view. Select the new tuple and observe this data below the output stream table:

    value=2, action=triple, newValue=6, path=[Entering port 1 for Name dispatch,Tripler.sbapp]
  11. In the Manual Input view, enter the following field values:

    Field Enter this value
    value 3
    action null
  12. Click Send Data, and two tuples arrive in the Application Output view. Select the new tuples and observe this data below the output stream table:

    value=3, action=null, newValue=6, path=[Entering port 2 for Broadcast dispatch,Doubler.sbapp]
    value=3, action=null, newValue=9, path=[Entering port 2 for Broadcast dispatch,Tripler.sbapp]
  13. When done, press F9 or click the Stop Running Application button.

This Sample's Files

The Extension Point sample is composed of following files:

ExtensionPoint.sbapp

The top-level application for this sample. Its input stream accepts an integer value and a string field, action, that determines what to do with the integer. The recognized values for action are double, triple, and null.

The following file is located in the same package folder as the sample operator's application files.

Multiplier.sbint

A StreamBase interface that defines two input streams and one output stream, and defines named schemas used by those streams.

The following files are located in the com.tibco.sb.sample.operator.modules package folder of the sample operator's src/main/eventflow project directory.

Doubler.sbapp

A module that implements the streams and schemas defined in the Multiplier.sbint interface. This module doubles its input value, and appends as a list(string) the StreamBase path through this module.

Tripler.sbapp

Another module that implements the Multiplier.sbint interface. This module performs the same actions as Doubler.sbapp except that it triples its input value.

Open ExtensionPoint.sbapp in Studio and look at the Properties view for the Extension Point operator named Multiply. The Concurrency tab is entirely responsible for directing input tuples to one or both of the referenced modules, either Doubler.sbapp or Tripler.sbapp:

  • If a tuple enters input port 2, the dispatch style is Broadcast, which means the tuple is sent to both modules.

  • If a tuple enters input port 1, the dispatch style is Name. In this case, the expression lower(action) must resolve to the identifier of one of the two modules ("double" or "triple") as defined in the Modules tab.

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_operator

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