Buffering Sample

This sample demonstrates the benefit of using buffering in the StreamBase client. The sample application contains an aggregate that calculates the average of a double field for all tuples processed.

For related information about enabling buffering in producer or enqueue clients, see the topic Creating Clients in the API Guide.

Importing This Sample into StreamBase Studio

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

  • From the top menu, click FileLoad StreamBase Sample.

  • Select this application from the Client APIs list.

  • Click OK.

StreamBase Studio creates a project for this sample.

Sample Location

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 Studio n.m Workspace\
      sample_operator
Windows Vista:
  C:\Users\username\Documents\StreamBase Studio n.m Workspace\
      sample_operator

This Sample's Files

The Buffering Sample consists of:

  • A StreamBase application, simple.sbapp

  • Enqueue programs (binaries) that use the StreamBase Java and C++ Client APIs.

  • Java and C++ source code for the Enqueue programs.

  • Either Microsoft Visual Studio .Net solution and project files (Windows) or a Makefile (UNIX) that can be used to build all of the sample source code. (In the Visual Studio files, the paths to find StreamBase include files and libraries are configured to run from the installation directory.)

Running the Buffering Sample

To run this sample:

Running the Buffering Sample in StreamBase Studio

  1. In the Package Explorer, double-click to open the simple.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.

  3. Add sbclient.jar to your CLASSPATH. The JAR can be found in the lib directory of your StreamBase installation. Add the sample directory to your CLASSPATH as well, so that java can find Enqueuer.class.

  4. Dequeue from the output stream with the following command:

    sbc dequeue &

  5. To run the Java Enqueuer, enter:

    java Enqueuer -b 1

  6. After a delay, you should see the number of tuples enqueued and the number of tuples enqueued per second.

  7. Run the Enqueue program again using -b 10 instead of -b 1 and observe the improvement.

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

Running the Buffering Sample in Terminal Windows

To run this sample:

  1. Launch a StreamBase Server on the sample application:

    sbd simple.sbapp

  2. Add sbclient.jar to your CLASSPATH. The JAR can be found in the lib directory of your StreamBase installation. Add the sample directory to your CLASSPATH as well, so that java can find Enqueuer.class.

  3. Dequeue from the output stream with this command:

    sbc dequeue

  4. To run the Java Enqueuer:

    java Enqueuer -b 1

  5. To run the C++ Enqueuer:

    Enqueuer -b 1

  6. After a delay, you should see the number of tuples enqueued and the number of tuples enqueued per second.

  7. Run the Enqueue program again using -b 10 instead of -b 1 and observe the improvement.

  8. Command line options can be given to each of the enqueuers. The following commands will display those options:

    java Enqueuer -h

    Enqueuer -h