First Application Sample

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.

Running the First Application Sample

Running firstapp.sbapp in StreamBase Studio

To start the First Application sample:

  1. 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.

  2. 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:

    1. Click HelpCheat Sheets.

    2. In the Cheat Sheet Selection list, expand StreamBase Studio and choose Getting Started.

    3. Click OK.

    4. Follow the procedure in the step titled, Testing Data Manually.

Enqueuing Data Manually in Studio

To enqueue data manually in Studio:

  1. Open the Manual Input view.

  2. In the Application Output view, make sure that the Output stream option is set to All streams.

  3. Enter IBM in the symbol field, and 10000 in the quantity field.

  4. Click Send Data to send this tuple to the application.

  5. Observe the output in the Application Output view:

    Because the quantity satisfies the Filter predicate, your tuple is passed through on the BigTrades stream.

  6. Enter 100 in the quantity field and click Send Data again.

  7. Observe that this time, your output appears in the AllTheRest output stream.

    Why? Because the quantity is below the predicate's threshold of 10000.

  8. Enter different values above and below the threshold, and see how your application responds. Try entering a nonvalid quantity like alpha.

Enqueuing Data Using a Feed Simulation in Studio

To enqueue test data using any of the three feed simulations:

  1. Open the Feed Simulations view.

  2. In the Feed Simulations view, select a feed simulation.

  3. Click Run.

    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.

  4. If you chose firstapp-enum.sbfs, let it run for five or ten seconds, then click Stop (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.

  5. 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.

  6. When done, press F9 or click the Stop Running Application button.

Running firstapp.sbapp in Terminal Windows

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:

  1. 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.

  2. In window 1, enter:

    sbd firstapp.sbapp

    A message indicates that the StreamBase Server is listening (waiting for tuples).

  3. 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.

Enqueuing Data Manually in Terminal Windows

To enqueue data manually:

  1. 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.

  2. Enter IBM,10000 in window 3.

  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.

  4. Enter FSLR, 100 in window 3.

  5. 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.

  6. Enter different values above and below the threshold, and verify that tuples are sent to the expected output stream.

Enqueuing Data Using a Feed Simulation in Terminal Windows

To enqueue data using any of the three available feed simulations:

  1. 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.

  2. 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
  3. In window 2, press Ctrl+C to close the enqueuer. Then run sbadmin shutdown to close the server.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, select FileLoad StreamBase Sample.

  • Select this sample from the Applications list.

  • Click OK.

StreamBase Studio creates a project for the sample.

Sample Location

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.