Contents
This sample, firstapp.sbapp
, demonstrates a StreamBase application with one notable characteristic: it is easy to create. You may have already created
it yourself, if you performed either the Getting Started Cheat Sheet (available from Studio's Welcome page and in the Help menu) or the tutorial in the Getting Started Guide.
The application is modest in functionality, but building it teaches you some important fundamentals including:
-
The general design process of defining input streams, schemas, operators, and output streams
-
Adding and connecting components in an EventFlow
-
Typechecking operators to ensure that streaming data can flow through the application without errors
-
Features of the SB Authoring and SB Test/Debug perspectives
-
Running the application in StreamBase Studio
-
Creating a feed simulator to enqueue test data automatically to the running application
In addition to the application, the installed First Sample includes two additional feed simulations. Thus, there are three simulations in total, each demonstrating a different way of modeling test data:
- firstapp-enum.sbfs
-
Also featured in the tutorial, generates values from a list of symbols and quantities, in random order. The enumeration also specifies the weights of the quantities.
- firstapp-trace1.sbfs
-
Uses an external comma-separated value data file,
firstapp-trace1.csv
, to explicitly list the order and values of tuples. - firstapp-trace2.sbfs
-
Uses values specified in another external comma-separated value data file,
firstapp-trace2.csv
, and also uses relative timestamps to control the rate of enqueuing.
To start the First Application sample:
-
In the Package Explorer, double-click to open the
firstapp.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.
The server is ready to receive input.
You can enqueue data in several different ways:
-
For instructions on enqueuing data manually, use the Getting Started Cheat Sheet:
-
Click
→ . -
In the Cheat Sheet Selection list, expand StreamBase Studio and choose Getting Started.
-
Click
. -
Follow the procedure in the step titled, Testing Data Manually.
-
To enqueue data manually in Studio:
-
Open the Manual Input view.
-
In the Application Output view, make sure that the Output stream option is set to
All streams
. -
Enter
IBM
in the symbol field, and10000
in the quantity field. -
Click
to send this tuple to the application. -
Observe the output in the Application Output view:
Because the quantity satisfies the Filter predicate, your tuple is passed through on the BigTrades stream.
-
Enter
100
in the quantity field and click again. -
Observe that this time, your output appears in the AllTheRest output stream.
Why? Because the quantity is below the predicate's threshold of 10000.
-
Enter different values above and below the threshold, and see how your application responds. Try entering a nonvalid quantity like
alpha
.
To enqueue test data using any of the three feed simulations:
-
Open the Feed Simulations view.
-
In the Feed Simulations view, select a feed simulation.
-
Click
.The Application Input view displays generated tuples enqueued from your Feed Simulation. At the same time, the Application Output view begins displaying tuples on the two output streams.
-
If you chose firstapp-enum.sbfs, let it run for five or ten seconds, then click
(otherwise it runs continuously). The other two feed simulators run to completion, but feel free to stop them when you have enough data.Note that stopping the feed simulation does not stop the application.
-
Observe the results in the Application Input and Application Output views. (If necessary, resize the views so that you can see their contents clearly.)
Tip
Click a row to display its field summary below the list, as shown in the next figure.
You should see trades values that are both above and below the threshold of 10000 that was set in your Filter operator.
-
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.
Set up the terminal windows using these steps:
-
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, enter:
sbd firstapp.sbapp
A message indicates that the StreamBase Server is listening (waiting for tuples).
-
In window 2, enter:
sbc dequeue
No output is displayed at this point, but the dequeuer is prepared to receive output from both of the application's output streams.
You are ready to enqueue data either manually or using a feed simulation.
To enqueue data manually:
-
In window 3, enter:
sbc enqueue TradesIn
The sbc command is now ready to send tuples to the TradesIn input stream, and waits for your keyboard input in window 3.
-
Enter
IBM,10000
in window 3. -
Observe this output in the dequeue window:
BigTrades,IBM,10000
Because the quantity satisfies the Filter predicate, your tuple is passed through on the BigTrades stream.
-
Enter
FSLR, 100
in window 3. -
Observe this output in the dequeue window:
AllTheRest,FSLR,100
Your output appears in AllTheRest because the quantity is below the predicate's threshold of
10000
. -
Enter different values above and below the threshold, and verify that tuples are sent to the expected output stream.
To enqueue data using any of the three available feed simulations:
-
In window 3, enter:
sbfeedsim
feed simulation
sbfeedsim firstapp-trace1.sbfs
For example:
sbfeedsim firstapp-trace1.sbfs
.Because
firstapp-enum.sbfs
runs continuously, consider limiting its execution. For example:sbfeedsim --max-tuples 100 firstapp-enum.sbfs
The other two feed simulators run to completion, but feel free to stop them when you have enough data.
-
Observe the output in the dequeue window. You should see trades on both output queues, according to the quantity. For example:
AllTheRest,NKE,400 AllTheRest,FSLR,400 BigTrades,GMCR,10000 AllTheRest,CMG,400 AllTheRest,CMG,1000 AllTheRest,FSLR,1000 BigTrades,FSLR,30000 BigTrades,FSLR,10000 AllTheRest,FSLR,400
-
In window 2, press Ctrl+C to close the enqueuer. Then run
sbadmin shutdown
to close the server.
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
Select this sample from the Applications list.
-
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_firstapp
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/firstapp
See Default Installation Directories for the default location of studio-workspace
on your system.