Package 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 Description static Schema
STAT_SCHEMA
The stats schema.static Schema
STAT_SCHEMA_V3
The v3 stats schema.
-
Constructor Summary
Constructors Constructor Description StreamBaseMonitor(StreamBaseClient client)
Create a monitoring object, which will connect to a server with the given StreamBaseClient object.StreamBaseMonitor(StreamBaseClient sbClient, String streamName)
ConstructorStreamBaseMonitor(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 Description void
addMonitorListener(MonitorListener listener)
Add a listener for snapshot information.void
close()
boolean
enableOperatorDetail(boolean enable)
Enable or disable operator details in snapshots such as operator type.protected void
finalize()
StreamBaseClient
getClient()
Get theStreamBaseClient
that this monitor is usingSchema
getStatsSchema()
Get the stats schemaString
getStatsStreamName()
Get the stats stream nameboolean
isClosed()
Indicates if the StreamBaseMonitor client is closedboolean
isStatsEnabled()
Determine if stats are availablestatic void
main(String[] args)
Main for testingvoid
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.
-
-
-
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
Constructor- Parameters:
sbClient
- StreamBase ClientstreamName
- Stream name- Throws:
StreamBaseException
- Error creating monitor
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
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 untilterminate
is called or the connection to the StreamBase server is disconnected. Any call toterminate
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.- 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 theStreamBaseClient
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
-
-