com.streambase.sb.monitor

## Class StreamBaseMonitor

- java.lang.Object
- - com.streambase.sb.monitor.StreamBaseMonitor

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class StreamBaseMonitor
      extends Object
      implements Closeable

  Monitors a StreamBase Server, and gathers statistics. Periodically sends Snapshot objects to all registered MonitorListeners.
  See Also:
    `Snapshot`, `MonitorListener`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) static String[]` | `modTagNames`
    `(package private) static Set<String>` | `modTags`
    `(package private) static String[]` | `opTagNames`
    `(package private) static Set<String>` | `opTags`
    `static Schema` | `STAT_SCHEMA` The stats schema.
    `static Schema` | `STAT_SCHEMA_V3` The v3 stats schema.
    `(package private) static String[]` | `streamTagNames` Total number of tuples passed through a stream
    `(package private) static Set<String>` | `streamTags`
    `(package private) static String[]` | `sysTagNames`
    `(package private) static Set<String>` | `sysTags`
    `(package private) static String[]` | `thrTagNames`
    `(package private) static Set<String>` | `thrTags`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StreamBaseMonitor(StreamBaseClient client)` Create a monitoring object, which will connect to a server with the given StreamBaseClient object.
    `StreamBaseMonitor(StreamBaseClient sbClient, String streamName)`
    `StreamBaseMonitor(StreamBaseURI uri)` Create a monitoring object, which will connect to a server with the given StreamBase URI.
    `StreamBaseMonitor(String uri)` Create a monitoring object The given uri can either be a StreamBaseURI or a filename.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addMonitorListener(MonitorListener listener)` Add a listener for snapshot information.
    `void` | `close()` close this monitor
    `boolean` | `enableOperatorDetail(boolean enable)` Enable or disable operator details in snapshots such as operator type.
    `protected void` | `finalize()`
    `StreamBaseClient` | `getClient()` Get the `StreamBaseClient` that this monitor is using
    `Schema` | `getStatsSchema()` Get the stats schema
    `String` | `getStatsStreamName()` Get the stats stream name
    `boolean` | `isClosed()` Indicates if the StreamBaseMonitor client is closed
    `boolean` | `isStatsEnabled()` Determine if stats are available
    `static void` | `main(String[] args)` Main for testing
    `void` | `removeMonitorListener(MonitorListener listener)` Remove a listener that was previously added.
    `void` | `removeMonitorListeners()` Remove all listeners.
    `protected void` | `reportMonitorStatus()` Report GC and memory usage, if log level debug is enabled.
    `void` | `run()` Read and process monitor snapshots from sbd.
    `void` | `terminate()` Ask the monitor to terminate.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### STAT_SCHEMA

          public static final Schema STAT_SCHEMA

      The stats schema.

    - #### STAT_SCHEMA_V3

          public static final Schema STAT_SCHEMA_V3

      The v3 stats schema.

    - #### sysTagNames

          static final String[] sysTagNames

    - #### opTagNames

          static final String[] opTagNames

    - #### thrTagNames

          static final String[] thrTagNames

    - #### modTagNames

          static final String[] modTagNames

    - #### streamTagNames

          static final String[] streamTagNames

      Total number of tuples passed through a stream

    - #### sysTags

          static final Set<String> sysTags

    - #### opTags

          static final Set<String> opTags

    - #### thrTags

          static final Set<String> thrTags

    - #### modTags

          static final Set<String> modTags

    - #### streamTags

          static final Set<String> streamTags

  - ### Constructor Detail

    - #### StreamBaseMonitor

          public StreamBaseMonitor(StreamBaseURI uri)
                            throws StreamBaseException

      Create a monitoring object, which will connect to a server with the given StreamBase URI. The connection will not be made until caller calls run().

      A null StreamBase URI will get the connection information from the streambase.uri property variable, if set. The default server is "sb://localhost:10000".

      Parameters:
        `uri` - URI of StreamBase server
      Throws:
        `StreamBaseException` - on error
      See Also:
        `StreamBaseURI`

    - #### StreamBaseMonitor

          public StreamBaseMonitor(StreamBaseClient client)
                            throws StreamBaseException

      Create a monitoring object, which will connect to a server with the given StreamBaseClient object.

      Note: The StreamBaseClient object is passed into this StreamBaseMonitor constructor. Therefore this StreamBaseMonitor does not "own" the StreamBaseClient object. It is the responsibility of the caller to close the StreamBaseClient object.

      Parameters:
        `client` - an already connected StreamBaseClient
      Throws:
        `StreamBaseException` - on error
      See Also:
        `StreamBaseClient`

    - #### StreamBaseMonitor

          public StreamBaseMonitor(String uri)
                            throws StreamBaseException

      Create a monitoring object The given uri can either be a StreamBaseURI or a filename. If it is a StreamBaseURI then the monitor will use it to connect to a StreamBaseServer for live monitoring. If a filename the StreamBaseMonitor will read stats from a file. This file is typically made by sbc dequeue system.stats. A empty or null uri will cause the StreamBaseMonitor to get uri information from the environment.

      Parameters:
        `uri` - A StreamBaseURI or filename.
      Throws:
        `StreamBaseException` - on error
      See Also:
        `StreamBaseURI`

    - #### StreamBaseMonitor

          public StreamBaseMonitor(StreamBaseClient sbClient,
                                   String streamName)
                            throws StreamBaseException

      Throws:
        `StreamBaseException`

  - ### Method Detail

    - #### finalize

          protected void finalize()

      Overrides:
        `finalize` in class `Object`

    - #### close

          public void close()

      close this monitor
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`

    - #### enableOperatorDetail

          public boolean enableOperatorDetail(boolean enable)

      Enable or disable operator details in snapshots such as operator type. Must be set before StreamBaseMonitor.run() is called. Setting after run is called has no effect.
      Parameters:
        `enable` - true: enable collection of Operator details; false: disable collection
      Returns:
        if operator details were previously enabled or disabled.
      Since:
        7.0.2

    - #### isClosed

          public boolean isClosed()

      Indicates if the StreamBaseMonitor client is closed
      Returns:
        true means this StreamBaseMonitor is moribund.
      Since:
        6.6.9

    - #### terminate

          public void terminate()

      Ask the monitor to terminate. Termination will occur after the next snapshot, or after the current snapshot if terminate() is invoked from within a MonitorListener's snapshotReceived() method.

    - #### run

          public void run()
                   throws StreamBaseException

      Read and process monitor snapshots from sbd. This function will block, and will not return until `terminate` is called or the connection to the StreamBase server is disconnected. Any call to `terminate` must be either from inside a MonitorListener, or from another thread.
      Throws:
        `StreamBaseException` - if a connection cannot be established with the server, or an error occurs while receiving a snapshot

    - #### reportMonitorStatus

          protected void reportMonitorStatus()

      Report GC and memory usage, if log level debug is enabled.

    - #### isStatsEnabled

          public boolean isStatsEnabled()

      Determine if stats are available
      Returns:
        true=stats are available false=either the server is not available, or stats are disabled on the server
      Since:
        7.0.2

    - #### addMonitorListener

          public void addMonitorListener(MonitorListener listener)

      Add a listener for snapshot information.

      If the given listener has already been added just return.

      Listeners are called in the order in which they were added.

      Parameters:
        `listener` - user-implemented MonitorListener to add

    - #### removeMonitorListener

          public void removeMonitorListener(MonitorListener listener)

      Remove a listener that was previously added.
      Parameters:
        `listener` - user-implemented MonitorListener to remove

    - #### removeMonitorListeners

          public void removeMonitorListeners()

      Remove all listeners.

    - #### getStatsStreamName

          public String getStatsStreamName()

      Get the stats stream name
      Returns:
        the stats stream name

    - #### getStatsSchema

          public Schema getStatsSchema()

      Get the stats schema
      Returns:
        the stats stream schema

    - #### getClient

          public StreamBaseClient getClient()

      Get the `StreamBaseClient` that this monitor is using
      Returns:
        `StreamBaseClient` in use by this monitor

    - #### main

          public static void main(String[] args)

      Main for testing
      Parameters:
        `args` - command line arguments

Copyright © 2015–2018 Cloud Software Group, Inc.. All rights reserved.