This sample demonstrates how to monitor the status of StreamBase clients using the Java Client API. The sample provides a Java StreamBase client application that connects to a simple EventFlow application running in StreamBase Server, and tracks the status of its own connection to the server in four ways:
It registers a callback to be notified of status changes.
It uses a timer to periodically check the status.
It uses a dequeue result to periodically check the status.
It sets the system property
true, which causes the StreamBase client to log the results at elevated log levels. This property is set as part of the run configuration saved as
ClientStatusMonitor.launch. See StreamBase Java Properties for more on this system property.
For detailed information about the API methods used in this sample, refer to the Java Client API Javadoc.
The Java code in this sample is delivered only in source code form. To build the code, you must load the sample into StreamBase Studio, which automatically builds the Java code.
In StreamBase Studio, import this sample with the following steps:
From the top-level menu, click> .
Select this application from the Applications list.
StreamBase Studio creates a project for each sample.
In the Project Explorer view, double-click to open
DoNothing.sbapp. 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 module.
Return to the SB Authoring perspective.
Run the ClientStatusMonitor Java application by right-clicking the
ClientStatusMonitor.launchfile in the Project Explorer view and selecting > .
Do not select the Java file itself and use > . This does run the client program, but unlike using the
.launchfile, this method does not set the required URI argument or the required Java system property. Thus, running the Java client application this way is guaranteed to fail.
Scroll to the right In the Console view, and observe the various connection status reports:
... INFO c.s.s.c.status.ClientStatusMonitor - Callback Status -> INFO c.s.s.c.status.ClientStatusMonitor - Periodic Check -> INFO c.s.s.c.status.ClientStatusMonitor - Dequeue -> ...
Return to the SB Test/Debug perspective. In the Manual Input tab, enqueue tuples on the input stream, and scroll right in the Console view to observe
Status=GOODevents in the output:
... Dequeue (Status=GOOD, ClientID=C3C33649299F0733053DBD822BC8B7D4, 1 tuples dequeued) Dequeue (Status=GOOD, ClientID=C3C33649299F0733053DBD822BC8B7D4, 2 tuples dequeued) ...
To stop running this sample requires two steps, in the following order:
Stop the client application by clicking the red button in the toolbar of the Console view.
Stop the EventFlow application by pressing F9 or clicking the Terminate EventFlow Fragment button.
The ClientStatusMonitor sample includes the following files:
Java client application that monitors its own connection status as described above.
Launch configuration file that (1) sets the system property described above, then (2) runs the Java client application with a default URI argument of
You can modify these settings by invoking> and selecting the configuration for
ClientStatusMonitorin the Java Application tree. (This launch configuration might not appear in the dialog until you have successfully run it at least once.)
Sample EventFlow application with a pass-through Map operator. The only purpose of this module is to present a running application to which the Java client program can connect.
Server configuration file that tells StreamBase Server to use TCP port 10000. Even though this is the StreamBase default port, you might have changed your Studio settings to use a non-default port, or to automatically select an alternate port if 10000 is in use. The presence of this configuration file overrides those settings.
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.
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 permission problems. The default workspace location for this sample is:
See Default Installation Directories for the default location of
studio-workspace on your system.