Contents
This sample uses a Merge operator to interlace trades from a Reuters and a Comstock
feed, based on trade time. The input streams contain the fields Symbol, Volume, PricePS (per share), Time, and
FeedID.
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
Merge.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
MergeOutoutput stream. No output is displayed at this point, but the dequeuer is prepared to receive output. This view eventually shows the output of the application. -
In the Manual Input view, select the
ComstockIninput stream -
Enter
amat,100,23,10, and0in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.Click , and observe that no output is displayed yet in the Application Output view.
-
Enter
amat,23,10, and1in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.Click Send Data, and observe that no output is displayed yet in the Application Output view.
-
Select the
ReutersIninput stream. -
Enter
intc,200,21,11, and0in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.Click Send Data, and observe this data appears in the Application Output view:
Symbol=amat, Volume=100, PricePS=23.0, Time=10, FeedID=0
-
Enter
intc,200,21,11, and1in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.Click Send Data, and observe this data appears in the Application Output view.
Symbol=amat, Volume=100, PricePS=23.0, Time=10, FeedID=1
-
Enter
msft,100,40,12, and0in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.Click Send Data, and observe that no further output is displayed yet in the Application Output view.
-
Enter
msft,100,40,12, and1in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.Click Send Data, and observe that no further output is displayed yet in the Application Output view.
-
Select the ComstockIn input stream.
-
Enter
amat,300,24,15, and0in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.Click Send Data, and observe this data appears in the Application Output view.
Symbol=intc, Volume=200, PricePS=21.0, Time=11, FeedID=0 Symbol=msft, Volume=100, PricePS=40.0, Time=12, FeedID=0
-
Enter
amat,300,24,15, and1in the Symbol, Volume, PricePS, Time, and FeedID fields, respectively.Click Send Data, and observe this data appears in the Application Output view.
Symbol=intc, Volume=200, PricePS=21.0, Time=11, FeedID=1 Symbol=msft, Volume=100, PricePS=40.0, Time=12, FeedID=1
-
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 Merge.sbappThe window shows
notice[StreamBaseServer] listening on port 10000. -
In window 2, type:
sbc dequeue MergeOutNo output is displayed at this point, but the dequeuer is prepared to receive output. This window eventually shows the output of the application.
-
In window 3, type:
sbc enqueueThe sbc command is now waiting for keyboard input. Type:
ComstockIn,amat,100,23,10,0No output is displayed yet in the dequeue window.
-
Type:
ComstockIn,amat,100,23,10,1.No output is displayed yet in the dequeue window.
-
Type:
ReutersIn,intc,200,21,11,0.Observe this line in the dequeue window:
amat,100,23.000000,10,0. -
Type:
ReutersIn,intc,200,21,11,1.Observe this line in the dequeue window:
amat,100,23.000000,10,1. -
Type:
ReutersIn,msft,100,40,12,0.No further output is displayed yet in the dequeue window.
-
Type:
ReutersIn,msft,100,40,12,1.No further output is displayed yet in the dequeue window.
-
Type:
ComstockIn,amat,300,24,15,0.Observe these lines in the dequeue window:
intc,200,21.000000,11,0 msft,100,40.000000,12,0
-
Type:
ComstockIn,amat,300,24,15,1.Observe these lines in the dequeue window:
intc,200,21.000000,11,1 msft,100,40.000000,12,1
-
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_operator" project.
-
From the top menu, in the SB Authoring perspective, selected File > New > EventFlow Application. Selected the
sample_operatorproject and enteredMergefor the diagram name. -
Created an input stream
-
Dragged an input stream from the palette to the canvas.
-
Clicked it on the canvas, which invoked the Input Stream Properties dialog window.
-
On the General tab, Name:
ReutersIn -
On the Edit Schema tab, added:
-
Field Name: Symbol, Type:
string, Size:5 -
Field Name: Volume, Type:
int -
Field Name: PricePS, Type:
double -
Field Name: Time, Type:
int -
Field Name: FeedID, Type:
int
-
-
-
Created another input stream
-
Dragged an input stream from the palette to the canvas.
-
Clicked it on the canvas, which invoked the Input Stream Properties dialog window.
-
On the General tab, Name:
ComstockIn -
On the Edit Schema tab, clicked the
Copy Schemaicon in the upper right corner. On the Copy Schema from Existing Component dialog, we selected:Project: sample_operator
Application: Merge
Copy schema from: ReutersIn Input Stream
-
-
Created a Merge operator:
-
Dragged a Merge operator from the palette to the canvas.
-
On the General tab, Name:
myMerge -
Connected the
ReutersInandComstockIninput streams to themyMergeoperator.
-
-
Set up the Merge operator:
-
On the Merge Settings tab, Field by which to merge tuples:
Time -
On the Group Options tab, Expression 1:
FeedID
-
-
Created an output stream:
-
Dragged an output stream from the palette to the canvas.
-
On the General tab, Name:
MergeOut -
Connected the
myMergeoperator to theMergeOutoutput stream.
-
