Contents
The nth_value.sbapp sample application demonstrates how
to use a custom C++ aggregate function.
This topic describes how to load and run the sample. For detailed information about the sample, see Creating Custom C++ Functions in the API Guide.
By default, the sample files are installed in:
-
On Windows:
C:\Program Files\StreamBase Systems\StreamBase.n.m\sample\custom-aggregate-function -
On UNIX:
/opt/streambase/sample/custom-aggregate-function
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_custom-aggregate-function Windows XP: C:\Documents and Settings\username\My Documents\StreamBase Studion.mWorkspace\ sample_custom-aggregate-function Windows Vista: C:\Users\username\Documents\StreamBase Studion.mWorkspace\ sample_custom-aggregate-function
The sample has the following files:
-
A sample configuration file,
sbd.sbconf, which tells the StreamBase Server to load the custom aggregate function. -
A sample application,
nth_value.sbapp, which uses the aggregate function. -
Dynamically linked library for the custom aggregate function.
-
The source code for the custom aggregate function,
NthValue.cpp -
Either Microsoft Visual Studio .NET solution and project files (Windows) or a Makefile (UNIX), which can be used to build all of the sample source code. (In the Visual Studio project files, the paths to the StreamBase include files and libraries are configured for the standard default installation directory. You may need to adjust these paths for your PC.)
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click → .
-
Select this sample from the Extending StreamBase list.
-
Click OK.
StreamBase Studio creates a project for the sample.
-
In the Package Explorer, double-click to open the
nth-value.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, leave the All selection.
-
In the Manual Input view, select the input stream.
-
Enter
1.1. -
Click Send Data, and observe no output. The aggregate window needs at least two tuples to produce output.
-
Enter
2.2. -
Click Send Data, and observe
2.2appears in the stream namedoutput_window_size_2. -
Using the same send technique, send
5.6and observe5.6on output_window_size_2 and 2.2 on output_window_size_3. -
Using the same send technique, send
and observe3.53.5on output_window_size_2 and 5.6 on output_window_size_3. -
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, launch a StreamBase Server on the sample application:
sbd -f sbd.sbconf nth_value.sbapp -
In window 2, run a dequeuer so that you can see the output that will be produced:
sbc dequeue -
In window 3, run an enqueuer:
sbc enqueue input -
Type numbers into the enqueuer, one number per line. After you enter the second number you should see output in window 2 from
output_windows_size_2. After you enter the third number you should see output fromoutput_window_size_3as well asoutput_window_size_2. For example, if you enter the numbers1.1,2.2,5.6, and3.5, then you should see the following output from the dequeuer:output_window_size_2,2.2
output_window_size_2,5.6
output_window_size_3,2.2
output_window_size_2,3.5
output_window_size_3,5.6 -
To see what happens when the aggregate function throws an exception, try enqueuing a number to the stream named
input_that_will_cause_an_error. -
In window 3, press Ctrl-C to close the enqueuer. Then run
sbadmin shutdownto close the server.
