Contents
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
streambase.client.log-connection-status
totrue
, which causes the StreamBase client to log the results at elevated log levels. This property is set as part of the run configuration saved asClientStatusMonitor.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.
Note
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.
The ClientStatusMonitor sample includes the following files:
- ClientStatusMonitor.java
-
Java client application that monitors its own connection status as described above.
- ClientStatusMonitor.launch
-
Launch configuration file that (1) sets the system property described above, then (2) runs the Java client application with a default URI argument of
sb://localhost:1000
.You can modify these settings by invoking
→ and selecting the configuration forClientStatusMonitor
in the Java Application tree. (This launch configuration might not appear in the dialog until you have successfully run it at least once.) - DoNothing.sbapp
-
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.
- sbd.sbconf
-
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.
-
In the Package 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 application.
-
Return to the SB Authoring perspective.
-
Run the ClientStatusMonitor Java application by right-clicking the
ClientStatusMonitor.launch
file in the Package Explorer view and selecting → .Note
Do not select the Java file itself and use → . This does run the client program, but unlike using the
.launch
file, 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=GOOD
events 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
Stop Running Application button.
-
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click
→ . -
Select this application from the Applications list.
-
Click OK.
StreamBase Studio creates a project for each sample.
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_client-status-monitor
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/client-status-monitor
See Default Installation Directories for the default location of studio-workspace
on your system.