Contents
The HeartbeatAggregate.sbapp sample uses a Heartbeat
operator to output the number of stock quotes received every five seconds. The actual
counting is done by an Aggregate operator, but it depends on the Heartbeat to trigger
output during periods when no quotes are received.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click → .
-
Select operator from the Applications list.
-
Click OK.
StreamBase Studio creates a single project for the operator samples.
By default, the sample files are installed in:
-
On Windows:
C:\Program Files\StreamBase Systems\StreamBase.n.m\sample\operator -
On UNIX:
/opt/streambase/sample/operator
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_operator Windows XP: C:\Documents and Settings\username\My Documents\StreamBase Studion.mWorkspace\ sample_operator Windows Vista: C:\Users\username\Documents\StreamBase Studion.mWorkspace\ sample_operator
-
In the Package Explorer, double-click to open the
HeartbeatAggregate.sbappapplication. 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.
-
In the Application Output view, select the
TicCountsstream. No output is displayed at this point, but the Output View is prepared to receive output. This view will eventually show the output of the application. -
In the Manual Input view, select the
InputTicsinput stream -
Enter
IBMfor symbol, and83.17for price. -
Click Send Data. Within five seconds, look for a tuple on the
TicCountsoutput stream, stating that one quote was received in the last five seconds. -
Click Send Data three times in rapid succession. Within five seconds, look for a tuple on the
TicCountsoutput stream, stating that three quotes were received in the last five seconds. -
Wait five seconds and look for a tuple on the
TicCountsoutput stream, stating that zero quotes were received in the last five seconds. -
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 three 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 HeartbeatAggregate.sbappThe window shows
notice[StreamBaseServer] listening on port 10000. -
In window 2, type:
sbc dequeue TicCountsNo output is displayed at this point, but the dequeuer is prepared to receive output of the application.
-
In window 3, type:
echo IBM,84.17 | sbc enqueue SetPriceWithin five seconds, look for a tuple in the dequeue window stating that one quote was received in the last five seconds.
-
Wait five seconds and look for another tuple in the dequeue window stating that zero quotes were received in the last five seconds.
-
In window 2, type: Ctrl-Z (Windows) or Ctrl-D (UNIX) to exit the sbc session.
-
In window 3, type the following command to terminate the server and dequeuer:
sbadmin shutdown
-
Launched StreamBase Studio
-
Created (or subsequently used) the
sample_operatorproject. -
From the top menu, in the SB Authoring perspective, selected → → . Selected the
sample_operatorproject and enteredHeartbeatAggregatefor the diagram name. -
Added an input stream:
-
Dragged an input stream from the palette to the canvas.
-
Clicked the new input stream to open its properties.
-
On the Input Stream Properties view General tab, added Name:
InputTics. -
On the Edit Schema tab, added:
-
Field Name:
symbol, Type:string, Size:4 -
Field Name:
price, Type:double, Size:8
-
-
-
Added a Map operator:
-
Dragged a Map operator from the palette to the canvas.
-
Dragged a connector from the
InputTicsinput stream to the Map operator. -
Selected the new Map operator. On the Properties view General tab, added Name:
Timestamp -
On the Output Settings tab:
-
Selected the
All input fields with specified changesoption. -
Clicked the button and added the following Output Fields row:
Action:
Add, Field Name:time, Expression:now()
-
-
-
Added a Heartbeat operator:
-
Dragged a Heartbeat operator from the palette to the canvas.
-
Connected the Map operator to the new Heartbeat operator.
-
Clicked the Heartbeat operator. On the Properties view's General tab, added Name:
EverySecond -
On the Output Settings tab, added:
-
Tuple output interval:
1(seconds) -
Input tuple timestamp field:
time -
Maximum delay:
0.01(seconds)
-
-
-
Added an Aggregate operator:
-
Dragged an Aggregate operator from the palette to the canvas. Placed it after the Heartbeat operator.
-
Connected the Heartbeat operator to the Aggregate operator.
-
Selected the Aggregate operator. On the Properties view General tab, added Name:
CountTics -
On the Dimensions tab, clicked the button. In the Edit dimension dialog, added:
-
Name:
time -
Type Field:
time -
Opening policy, Open per, Advance:
5, Offset:0 -
Window size
Close and emit after 5
Clicked .
-
-
On the Aggregate functions tab, clicked the button twice and added these two rows:
-
-
Added an output stream:
-
Dragged an output stream from the palette to the canvas, placing it after the Aggregate operator.
-
Connected the Aggregate operator to the output stream.
-
Selected the new output stream. On the Properties view General tab, added Name:
TicCounts
-
