- Index

< Previous |  | Next >

# Client Status Monitor Sample

## Introduction

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:

1. It registers a callback to be notified of status changes.

2. It uses a timer to periodically check the status.

3. It uses a dequeue result to periodically check the status.

4. It sets the system property `streambase.client.log-connection-status` to `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.

### 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.

## Importing This Sample into StreamBase Studio

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

- From the top-level menu, click File → Load StreamBase Sample.

- Select this application from the Applications list.

- Click OK.

StreamBase Studio creates a project for each sample.

## Running This Sample in Studio

1. In the Project Explorer view, double-click to open `DoNothing.sbapp`. 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 module.

3. Return to the SB Authoring perspective.

4. Run the ClientStatusMonitor Java application by right-clicking the `ClientStatusMonitor.launch` file in the Project Explorer view and selecting Run As → ClientStatusMonitor.

   ### Note

   Do not select the Java file itself and use Run As → Java Application. 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.

5. 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 ->
       ...

6. 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)
       ...

7. To stop running this sample requires two steps, in the following order:

   1. Stop the client application by clicking the red Terminate button in the toolbar of the Console view.

   2. Stop the EventFlow application by pressing F9 or clicking the Terminate EventFlow Fragment button.

## This Sample's Files

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 Run → Run Configurations and selecting the configuration for `ClientStatusMonitor` 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.

## Sample Location

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 permission problems. The default workspace location for this sample is:

    studio-workspace/sample_client-status-monitor

See Default Installation Directories for the default location of `studio-workspace` on your system.