Contents
The Bsort.sbapp
sample application uses a BSort operator to reorder trades by time, for an input stream where trades come in in random order.
The input stream contains the fields Symbol
, Volume
, and Time
. It is interesting to compare the results of running this application with two passes and with six passes. This topic describes the Bsort sample.
-
In the Package Explorer, double-click to open the
Bsort.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.
-
In the Application Output view, select the StockOut output stream. No output is displayed at this point, but the dequeuer is prepared to receive output. This view will eventually show the output of the application.
-
In the Manual Input view, select the StockIn input stream.
-
Enter
msft
,100
, and10
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
msft
,100
, and30
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
intc
,100
, and5
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=intc, Volume=100, Time=5
-
Enter
msft
,100
, and25
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=msft, Volume=100, Time=10
-
Enter
amat
,100
, and2
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=amat, Volume=100, Time=2
-
Enter
intc
,100
, and15
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=intc, Volume=100, Time=15
-
Enter
msft
,100
, and40
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=msft, Volume=100, Time=25
Note that two passes are insufficient to order this input stream.
-
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 Bsort.sbapp
.The window shows
notice[StreamBaseServer] listening on port 10000
. -
In window 2, type:
sbc dequeue
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 enqueue StockIn
The sbc command is now awaiting keyboard input. Then type:
msft,100,10
.No output is displayed yet in the dequeue window.
-
Type:
msft, 100, 30
No output is displayed yet in the dequeue window.
-
Type:
intc, 100, 5
Observe this line in the dequeue window:
StockOut,intc,100,5
. -
Type:
msft, 100, 25
Observe this line in the dequeue window:
StockOut,msft,100,10
. -
Type:
amat, 100, 2
Observe this line in the dequeue window:
StockOut,amat,100,2
. -
Type:
intc, 100, 15
Observe this line in the dequeue window:
StockOut,intc,100,15
. -
Type:
msft, 100, 40
Observe this line in the dequeue window:
StockOut,msft,100,25
.Note that two passes are insufficient to order this input stream.
-
Press Ctrl+Z (Windows) or Ctrll+D (UNIX) in windows 2 and 3 to stop the sbc sessions.
-
In window 2 or 3, enter
sbadmin shutdown
to stop the server.
-
Return to the Authoring Perspective.
-
In the Package Explorer, right-click on
Bsort.sbapp
, and select . -
In the Bsort.sbapp view, click on the myBSort operator.
-
In the Properties view, click on the Sort Settings tab.
-
Change the value in the Tuples, using a buffer size of field from
2
to6.
-
Click OK.
→ , enter a new application name, and click -
Select the modified application in the Package Explorer, then click the
button. -
In the Application Output view, select the StockOut output stream. No output is displayed at this point, but the dequeuer is prepared to receive output. This view will eventually show the output of the application.
-
In the Manual Input view, select the StockIn input stream.
-
Enter
msft
,100
, and10
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
msft
,100
, and30
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
intc
,100
, and5
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
msft
,100
, and25
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
amat
,100
, and2
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
intc
,100
, and15
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe that no output is displayed yet in the Application Output view. -
Enter
msft
,100
, and40
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=amat, Volume=100, Time=2
-
Enter
intc
,100
, and20
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=intc, Volume=100, Time=5
-
Enter
intc
,100
, and18
in the Symbol, Volume, and Time fields, respectively. -
Click
, and observe this line in the Application Output view:Symbol=msft, Volume=100, Time=10
Note that 6 passes are sufficient to order this input stream.
-
When done, press F9 or click the Stop Running Application button.
-
In StreamBase Studio, double-click your copy of the
sbapp
file to open it. -
Change the value in the Tuple buffer size field from
2
to6
. -
Click OK.
-
Save the application.
-
Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to your workspace copy of the sample, as described above.
-
In window 1, type:
sbd Bsort.sbapp
The window shows this output:
notice[StreamBaseServer] listening on port 10000
. -
In window 2, type:
sbc dequeue
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 enqueue StockIn
The sbc command is now awaiting keyboard input. Then type:
msft,100,10
.No output is displayed yet in the dequeue window.
-
Type:
msft, 100, 30
No output is displayed yet in the dequeue window.
-
Type:
intc, 100, 5
No output is displayed yet in the dequeue window.
-
Type:
msft, 100, 25
No output is displayed yet in the dequeue window.
-
Type:
amat, 100, 2
No output is displayed yet in the dequeue window.
-
Type:
intc, 100, 15
No output is displayed yet in the dequeue window.
-
Type:
msft, 100, 40
Observe this line in the dequeue window:
StockOut,amat,100,2
. -
Type:
intc, 100, 20
Observe this line in the dequeue window:
StockOut,intc,100,5
. -
Type:
intc, 100, 18
Observe this line in the dequeue window:
StockOut,msft,100,10
Note that 6 passes are sufficient to order this input stream.
-
Press Ctrl+Z (Windows) or Ctrl+D (UNIX) to exit the sbc session.
-
In window 3, type:
sbadmin shutdown
This command terminates the server and dequeuer.
Tip
The Group By
fields can be used to order within a set of tuples, where the value of the Expression is the same. (The Expression can simply
be an input field.) This sets up a buffer for each set of tuples rather one buffer for all the tuples in the stream.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
Select operator from the Data Constructs and Operators category.
-
Click OK.
StreamBase Studio creates a single project for the operator samples.
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_operator
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/operator
See Default Installation Directories for the default location of studio-workspace
on your system.