EventFlow Function Sample

Introduction

This sample application demonstrates three ways to apply an algorithm to data on a stream. Using Map operators, it converts temperature data in degrees Celsius to degrees Fahrenheit, by applying:

  1. A function on a stream.

  2. A global function defined as a constant.

  3. An EventFlow expression.

StreamBase expression language functions can be defined as constant expressions or passed on a stream. Functions are a StreamBase data type. They return a declared data type and can accept any other data type as arguments. In this sample, there is one double argument and a double result.

The Map operator UseGlobalExpression invokes a function that was defined as a constant on the project's Definitions tab using the Add Constant button. Map operator UseFcnFromData applies a function added to the input stream by Map operator CreateFcn in a field called to_fahr. Map operator UseExpression, which evaluates an expression rather than a function to transform its input, is included for comparison purposes.

This Sample's Files

The Function sample consists of the project folder, temp-conversions, containing the application, function.sbapp.

Running This Sample in StreamBase Studio

To run this sample:

  1. In the Package Explorer view, double-click to open the function.sbapp application. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. Open the Feed Simulations tab.

  4. Select the Manual Input tab.

  5. Enter a value for a temperature in temp_cel in the celsius input stream and click Send Data.

  6. Observe that the temp_f_stream, temp_f_fcn, and temp_f_expr output values are identical.

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

Running This Sample in Terminal Windows

This section describes how to run the sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open five terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.

  2. In window 1, type:

    sbd function.sbapp

    The window shows notice[StreamBaseServer] listening on port 10000.

  3. In window 2: type:

    sbc dequeue fahrFcn

    No output is displayed at this point, but the dequeuer is prepared to receive output. This window will eventually show the output of the application.

  4. In window 3: type:

    sbc dequeue fahrStream

    No output is displayed at this point, but the dequeuer is prepared to receive output. This window will eventually show the output of the application.

  5. In window 4: type:

    sbc dequeue fahrExpr

    No output is displayed at this point, but the dequeuer is prepared to receive output. This window will eventually show the output of the application.

  6. In window 5, type:

    sbc enqueue celsius

    The sbc command is now awaiting keyboard input. Then type: 0.

    Windows 2, 3, and 4 display 32.0.

  7. In window 5, type:

    100

    Windows 2, 3, and 4 display 212.0.

  8. In Window 5, type: Ctrl+Z (Windows) or Ctrl+D (UNIX) to stop the sbc command.

  9. In window 5, type the following command to terminate the server and dequeuer:

    sbadmin shutdown

Importing This Sample into StreamBase Studio

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

  • From the top menu, select FileLoad StreamBase Sample.

  • Type function in the search field to narrow the list of choices.

  • From the Applications category, select function.

  • Click OK.

StreamBase Studio creates a project for the sample.

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_function

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

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/function

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