Creating a Simple EventFlow Module

This topic provides a tutorial for populating an empty EventFlow module with components that implement an EventFlow fragment for a simple stock trading application.

Preliminary Steps

Before building your module:

  1. Make sure you are in StreamBase Studio's SB Authoring perspective, as described in step 1 of the previous page.

  2. In Studio's top-level menu, invoke WindowPreferences on Windows, or StreamBase Studio m.nPreferences on macOS. In the left side contents panel, expand StreamBase Studio and open the Authoring page. Verify that the check box for Automatically typecheck components is selected.

    (To learn more about typechecking, see About Typechecking.)

  3. The previous page took you through the creation of a new EventFlow Fragment project named firstapp. The new project contains a new, empty EventFlow module, firstapp.sbapp.

    If this module is not currently open in an EventFlow Editor, double-click firstapp.sbapp in the Project Explorer to open it.

    Notice the Palette view on the bottom left under the Project Explorer view. Whenever an EventFlow module is open and its canvas is displayed, the palette is loaded with icons that represent the components you will use to design your EventFlow module. The icons are organized in drawers of different component types, as shown in the figure below.

    The Palette view is empty when an editor other than an EventFlow module's canvas is in the foreground.

Building Your First EventFlow Module

Follow this procedure to develop the firstApp.sbapp module.

  1. Add an Input Stream and define its schema.

    1. In the Palette view, open the Streams drawer, then drag an Input Stream icon from the palette into your EventFlow canvas.

      Notice the blue background of the Input Stream icon, which indicates the icon is selected.

    2. When you select a component in an EventFlow Editor, Studio opens its Properties view. In the image above, the Properties view is seen below the Editor's canvas.

    3. On the canvas, type over the default name InputStream to rename it TradesIn. (You can also do this by typing TradesIn in the Name field of the General tab.)


      Get in the habit of naming components at the time you create them. While StreamBase Studio always chooses default names for new components that do not conflict with others, the ideal is to rename them as you go to more accurately reflect their function or role in your module.

    4. Your TradesIn Input Stream now needs a schema. In the Properties view, select the Edit Schema tab. Provide a simple two-field schema by clicking the Add button twice to add one row for each schema field. Enter these values in the two rows:

      Field Name Type Description
      symbol string Stock symbol
      quantity int Number of shares

      (The description field is optional but recommended.)

    5. Apply your changes by clicking a blank area on the canvas, or by clicking the Apply and Typecheck button () near the top-right area of the Properties view. This forces Studio to typecheck your module now, instead of waiting for it to happen automatically.

    6. Notice that typechecking does not save the module. You can write the module file to disk at any time with FileSave or Ctrl+S (Windows) or command+S (macOS), or by clicking the Save button in the main toolbar.

  2. Add and configure a Filter operator with the following steps.

    1. From the Operators and Adapters drawer of the Palette view, drag a Filter operator onto the canvas. Its default name is Filter. The canvas should now look similar to this:

    2. Notice the Outline view on the right side of the canvas, which provides a tree view of all the components in your module. This view can be helpful for navigating large modules with many components.

    3. Double-click the Filter instance on the canvas (or in the Outline view) to select the component and opens its Properties view.

    4. Rename the operator to TradeFilter, using either the canvas or the General tab of the Properties view.

    5. Select the Predicate Settings tab. Notice that a row in the Predicates table already exists for output port 1, with predicate expression true. Edit this expression in the Predicate column, and specify:

      quantity >= 10000


      A predicate is a StreamBase expression that resolves to either true or false for field values in a tuple. A predicate expression can include variables or constants defined within the scope of a module or operator. We are specifying a predicate that resolves to true for tuples containing trades of 10000 shares or more. For tuples having a smaller quantity, the predicate expression returns false.

    6. As currently configured, the TradeFilter operator discards tuples whose quantity value is less than 10000. Instead of discarding them, select check box for the option Create output port for non-matching tuples. This creates output port 2.

    At this point, your Filter operator's Properties view looks like the following:

    At run time, the Filter operator evaluates each tuple as it arrives from the Input Stream. If you had defined multiple predicates, they would be evaluated in order. The first predicate that returns true causes the operator to emit the tuple on its output port immediately, and any later predicates are ignored.

    We have only one predicate, so each tuple is dequeued either on output port 1 if true, or on output port 2 if false.

  3. The canvas shows input and output ports as small black squares. Input ports are on the left side of components and output ports are on their right side. If there are multiple ports, the uppermost square represents port 1; the next square down represents port 2, and so on. Your Filter operator now has an extra output port, which you configured in the preceding step.

    On the canvas, click and hold the output port at the tip of the TradesIn arrow and drag the resulting arc to the input port on TradeFilter.

    Arcs represent internal streams within EventFlow modules. When you connect the two components, the input stream and the filter operator backgrounds turn white, indicating that the operation has successfully passed typechecking.

    For more about typechecking, see About Typechecking below.

  4. Add and connect the output streams:

    1. Drag an Output Stream icon from the Palette view into the canvas, and drop it on the right of the Filter operator. Rename this stream BigTrades.

    2. In the canvas, draw an arc from the upper output port of the Filter operator to the input port of the BigTrades output stream. When you hover the mouse pointer over the left end of the arc you just inserted, the canvas looks similar to the following.

    3. Add a second Output Stream in the same way, dropping it below the BigTrades output stream. Change the new stream's name to AllTheRest.

    4. Connect the lower output port of the Filter operator to the AllTheRest Output Stream.

      The final layout of your EventFlow module should look similar to the following:

  5. Optional. If your canvas looks a little disorganized, try one or both of these adjustments:

    • To automatically arrange the components neatly on the canvas, select EventFlowLayout Application or press Ctrl+L (Windows) or command+L (macOS).

    • To rearrange the arcs around components (such as when an arc overlaps a component's name), select EventFlowReroute Arcs.

  6. Use FileSave, Ctrl+S, command+S, or click the Save button in the Studio toolbar to save your EventFlow module.

About Typechecking

Typechecking validates the design of your modules as you build them. StreamBase Studio inspects each component of a module and will not run it if typechecking errors exist. One of the key advantages of designing in StreamBase Studio is that typechecking occurs constantly and automatically as you work, so you can avoid accumulating problems.

Conceptually, typechecking occurs from the starting points of the module (usually the left side), and proceeds to the downstream components (typically those connected on the right). When the typecheck process finds an error condition, the background color of the failing component turns red, and downstream components cannot be typechecked further.

Typechecks can fail for a variety of reasons, including:

  • Not providing a schema for an input stream.

  • Using duplicate field names in a schema.

  • Declaring a schema for an operator that is in conflict with the schema of the previous upstream connected operator.

  • Entering a wrong or misspelled field name in an expression in a component's properties settings.

  • Using a field name in an inappropriate way, such as specifying a int field in an expression that expects a timestamp.

  • Using invalid expression language features, such as an invalid identifier or function name, or providing a function with too many or too few arguments.

  • Using incorrectly specified operator parameters.

When you hover the mouse pointer over an operator with a typechecking error, Studio shows a tooltip that explains the error.