Contents
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:
-
A function on a stream.
-
A global function defined as a constant.
-
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
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.The Function sample consists of the project folder, temp-conversions, containing the application, function.sbapp
.
To run this sample:
-
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. -
Click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
Open the Feed Simulations tab.
-
Select the Manual Input tab.
-
Enter a value for a temperature in
temp_cel
in thecelsius
input stream and click . -
Observe that the
temp_f_stream
,temp_f_fcn
, andtemp_f_expr
output values are identical. -
When done, press F9 or click the
Stop Running Application button.
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.
-
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.
-
In window 1, type:
sbd function.sbapp
The window shows
notice[StreamBaseServer] listening on port 10000
. -
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.
-
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.
-
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.
-
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
. -
In window 5, type:
100
Windows 2, 3, and 4 display
212.0
. -
In Window 5, type: Ctrl+Z (Windows) or Ctrl+D (UNIX) to stop the sbc command.
-
In window 5, type the following command to terminate the server and dequeuer:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
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.
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 the permission problems that can occur when trying to work with the initially installed location of the sample. 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.