Contents
The log.sbapp application demonstrates how to use a
custom C++ simple function.
This topic describes how to load and run the sample. For detailed information about the sample, see the topic, Creating Custom C++ Functions, in the API Guide.
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.
By default, the sample files are installed in:
-
On Windows:
C:\Program Files\StreamBase Systems\StreamBase.n.m\sample\custom-simple-function -
On UNIX:
/opt/streambase/sample/custom-simple-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-simple-function Windows XP: C:\Documents and Settings\username\My Documents\StreamBase Studion.mWorkspace\ sample_custom-simple-function Windows Vista: C:\Users\username\Documents\StreamBase Studion.mWorkspace\ sample_custom-simple-function
The sample has the following files:
-
A sample configuration file,
sbd.sbconf, which tells StreamBase Server to load the custom simple function. -
A sample application,
log.sbapp, which uses the function. -
Dynamically linked library for the custom simple function.
-
The source code for the custom simple function,
LogFunction.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 the Package Explorer, double-click to open the
log.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 output stream.
-
In the Manual Input view, select the input stream.
-
Enter
1. -
Click , and observe
0.0appears in the output stream. -
Enter
10. -
Click , and observe
2.302585092994046appears in the output stream. -
Using the same send technique, send
50and100, and observe3.912023005428146and4.605170185988092appears respectively in the output stream. -
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 instance on the sample application:
sbd -f sbd.sbconf log.sbapp -
In window 2, run a dequeuer so that you can see the output that will be produced:
sbc dequeue output -
In window 3, run an enqueuer:
sbc enqueue input -
Type numbers into the enqueuer in window 3, one number per line. For example, if you enter the numbers
1,10,50, and100, you should see the following output from the dequeuer in window 2:0
2.30258509299405
3.91202300542815
4.60517018598809 -
To see what happens when the function throws an exception, try enqueuing a negative number.
-
In window 2, press Ctrl-C to close the enqueuer. Then run
sbadmin shutdownto close the server.
