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:
  • Field Details

    • 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.
    • streamTagNames

      static final String[] streamTagNames
      Total number of tuples passed through a stream
    • sysTags

      static final Set<String> sysTags
      System tags
    • opTags

      static final Set<String> opTags
      Operation tags
    • thrTags

      static final Set<String> thrTags
      Thread tags
    • modTags

      static final Set<String> modTags
      Module tags
    • streamTags

      static final Set<String> streamTags
      Stream tags
    • decisionTableTags

      static final Set<String> decisionTableTags
      Decision table tags
  • Constructor Details

    • 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:
    • 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:
    • 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:
    • StreamBaseMonitor

      public StreamBaseMonitor(StreamBaseClient sbClient, String streamName) throws StreamBaseException
      Constructor
      Parameters:
      sbClient - StreamBase Client
      streamName - Stream name
      Throws:
      StreamBaseException - Error creating monitor
  • Method Details

    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • 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) throws IllegalArgumentException
      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
      Throws:
      IllegalArgumentException - listener is null
    • removeMonitorListener

      public void removeMonitorListener(MonitorListener listener)
      Remove a listener that was previously added.

      If listener was not previously added this method quietly does nothing

      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