Class Monitor
- java.lang.Object
-
- net.sf.eBusx.monitor.Monitor
-
- All Implemented Interfaces:
EObject
public final class Monitor extends java.lang.Object implements EObject
This class provides the ability to instrumenteBus objectsand monitor those instrumented object's status. The first step is toopen a Monitorinstance. Note that only oneMonitormay be opened and it stays open as long as the JVM is running. The next step isregistering eBus objects. Once registered, these objects mayreport on-going statusandtransient events. When an eBus object is no longer operational, it should bede-registeredfromMonitor.Note:
Monitordoes not maintain a strong reference to registered eBus objects. This means that an eBus object can be finalized while still registered withMontior. If this happens,Monitorwill automatically de-register the finalized eBus object.Monitorpublishes:-
ApplicationInforeporting the monitor's opening, -
PersistentStatusMessagereporting an update to an eBus object's on-going status, and -
TransientStatusMessagereporting an eBus object's transient event.
Monitoralso handles the following requests:-
ApplicationInfoRequest: request for monitor's application information.ApplicationInfoReplyis sent in reply. -
MonitoredObjectRequest: request for current on-going registered eBus objects.MonitoredObjectReplyis sent in reply containingPersistentStatusMessages.
Note: there is no way to request previously post transient events. These can only be received when actively subscribed to transient status events.
See
package documentationfor a detailed explanation on how to useMonitor. The package documentation provides detailed explanation on how to instrument an eBus object and monitor updates.- Author:
- Charles Rapp
- See Also:
openMonitor(String, String, String, String, String, EField),getMonitor()
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAPP_INFO_REQUEST_SUBJECTApplicationInfoRequestis advertised with the subject "/eBus/monitor/request/app-info" to form request key.static java.lang.StringDEREGISTER_ACTION_NAMEMonitorUpdateaction name is "deregistered".static java.lang.StringMONITOR_NAMEeBus object name is ""eBus monitor"".static longMONITOR_PUBLISHER_IDMonitor publisher identifier is -2001L.static java.lang.StringMONITOR_UPDATE_FORMATMONITOR_UPDATE_FORMATis advertised with the subject "/eBus/monitor/update/%s/%s" with host and application name to form this notification key.static java.lang.StringONGOING_REQUEST_SUBJECTMonitoredObjectRequestis advertised with the subject "/eBus/monitor/request/on-going" to form request key.static java.lang.StringREGISTER_ACTION_NAMEMonitorUpdateaction name is "registered".-
Fields inherited from interface net.sf.eBus.client.EObject
NAME_NOT_SET
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringapplicationName()Returns configured application name.EFieldattributes()Returns application attributes.java.lang.Stringcopyright()Returns application copyright.voidderegister(EObject obj)Removes a registered eBus object from the monitor subsystem, retracting its published status and transient event feeds.java.lang.Stringdescription()Returns application description.static MonitorgetMonitor()Returns singleton monitor instance.java.lang.StringhostName()Returns configured host name.java.lang.Stringname()ReturnsMONITOR_NAME.static MonitoropenMonitor(java.lang.String host, java.lang.String appName, java.lang.String version, java.lang.String copyright, java.lang.String description, EField attributes)Creates, starts, and returns singleton monitor instance.voidregister(EObject obj)Registers a monitorable object and returns unique monitor identifier associated with registered object.voidstartup()Creates, registers, and starts monitor publisher and replier eBus objects.voidtransientStatus(ActionLevel actionLevel, java.lang.String actionName, java.lang.String actionMsg, EObject obj)Posts a one-time transient event for the given monitorable object.voidupdate(ActionLevel actionLevel, java.lang.String actionName, java.lang.String actionMsg, EObject obj)Updates the monitorable object on-going status with the given parameters.java.lang.Stringversion()Returns configured application version.
-
-
-
Field Detail
-
MONITOR_PUBLISHER_ID
public static final long MONITOR_PUBLISHER_ID
Monitor publisher identifier is -2001L.- See Also:
- Constant Field Values
-
MONITOR_NAME
public static final java.lang.String MONITOR_NAME
eBus object name is ""eBus monitor"".- See Also:
- Constant Field Values
-
REGISTER_ACTION_NAME
public static final java.lang.String REGISTER_ACTION_NAME
MonitorUpdateaction name is "registered".- See Also:
- Constant Field Values
-
DEREGISTER_ACTION_NAME
public static final java.lang.String DEREGISTER_ACTION_NAME
MonitorUpdateaction name is "deregistered".- See Also:
- Constant Field Values
-
MONITOR_UPDATE_FORMAT
public static final java.lang.String MONITOR_UPDATE_FORMAT
MONITOR_UPDATE_FORMATis advertised with the subject "/eBus/monitor/update/%s/%s" with host and application name to form this notification key.- See Also:
- Constant Field Values
-
APP_INFO_REQUEST_SUBJECT
public static final java.lang.String APP_INFO_REQUEST_SUBJECT
ApplicationInfoRequestis advertised with the subject "/eBus/monitor/request/app-info" to form request key.- See Also:
- Constant Field Values
-
ONGOING_REQUEST_SUBJECT
public static final java.lang.String ONGOING_REQUEST_SUBJECT
MonitoredObjectRequestis advertised with the subject "/eBus/monitor/request/on-going" to form request key.- See Also:
- Constant Field Values
-
-
Method Detail
-
name
public java.lang.String name()
ReturnsMONITOR_NAME.
-
startup
public void startup()
Creates, registers, and starts monitor publisher and replier eBus objects.- Specified by:
startupin interfaceEObject- See Also:
EObject.shutdown()
-
hostName
public java.lang.String hostName()
Returns configured host name. Please note that this name is not necessarily a network host name.- Returns:
- host name.
-
applicationName
public java.lang.String applicationName()
Returns configured application name.- Returns:
- application name.
-
version
public java.lang.String version()
Returns configured application version.- Returns:
- application version.
-
copyright
@Nullable public java.lang.String copyright()
Returns application copyright. May return anullvalue.- Returns:
- application copyright.
-
description
@Nullable public java.lang.String description()
Returns application description. May return anullvalue.- Returns:
- application description.
-
attributes
@Nullable public EField attributes()
Returns application attributes. May return anullvalue.- Returns:
- application attributes.
-
getMonitor
@Nullable public static Monitor getMonitor()
Returns singleton monitor instance. Returnsnullif monitor was not previouslyopened.- Returns:
- singleton monitor instance.
-
register
public void register(EObject obj)
Registers a monitorable object and returns unique monitor identifier associated with registered object. The object's initial persistent status is set toActionLevel.NO_ACTION, "Registered". An eBus object must successfully register prior toupdatingits status or posting atransientevent.Note: monitor does not maintain a strong references to
obj. If this eBus object is finalized while still registered withMonitor, then monitor is informed of this finalization and automatically de-registers the finalized eBus object.- Parameters:
obj- register this monitorable object.- Throws:
java.lang.NullPointerException- ifobjisnull.java.lang.IllegalArgumentException- ifobjisnullorEObject.name()returns anullor empty string.- See Also:
update(ActionLevel, String, String, EObject),transientStatus(ActionLevel, String, String, EObject),deregister(EObject)
-
update
public void update(ActionLevel actionLevel, java.lang.String actionName, @Nullable java.lang.String actionMsg, EObject obj)
Updates the monitorable object on-going status with the given parameters.- Parameters:
actionLevel- the action level.actionName- the action name.actionMsg- the human-readable action message. May benullor an empty string.obj- the registered monitorable object.- Throws:
java.lang.NullPointerException- ifobjisnull.java.lang.IllegalArgumentException- ifactionNameis eithernullor an empty string.java.lang.IllegalStateException- ifobjis not registered.- See Also:
transientStatus(ActionLevel, String, String, EObject),register(EObject),deregister(EObject)
-
transientStatus
public void transientStatus(ActionLevel actionLevel, java.lang.String actionName, @Nullable java.lang.String actionMsg, EObject obj)
Posts a one-time transient event for the given monitorable object.- Parameters:
actionLevel- the action level.actionName- the action name.actionMsg- the human-readable action message. May benullor an empty string.obj- the registered monitorable object.- Throws:
java.lang.NullPointerException- ifobjisnull.java.lang.IllegalArgumentException- ifactionNameis eithernullor an empty string.java.lang.IllegalStateException- ifobjis not registered.- See Also:
register(EObject),update(ActionLevel, String, String, EObject),deregister(EObject)
-
deregister
public void deregister(EObject obj)
Removes a registered eBus object from the monitor subsystem, retracting its published status and transient event feeds.- Parameters:
obj- remove this monitorable instance.- Throws:
java.lang.NullPointerException- ifobjisnull.- See Also:
update(ActionLevel, String, String, EObject),transientStatus(ActionLevel, String, String, EObject),register(EObject)
-
openMonitor
public static Monitor openMonitor(java.lang.String host, java.lang.String appName, java.lang.String version, @Nullable java.lang.String copyright, @Nullable java.lang.String description, @Nullable EField attributes)
Creates, starts, and returns singleton monitor instance. Please note that when calling this method for the first time, the method blocks untilMonitorinstance is started. Parameter values are left up to the user to decide what constitutes a valid setting. Note that these values should be meaningful to both the application and to those monitoring the application.For example, consider
host. A natural reaction is to use the name configured by the network support team. But these names are often arcane and meaningful only to network support. The application team may refer to this host as "uat-ny-1" - meaning the first user acceptance testing host (uat) site in New York. SinceMonitoroperates at the application level, this would be a better host name. This also applies to the remaining parameters.The
attributesparameter allows an application to add any number of additional settings by extending an eBusEField. A partial example is:import net.sf.eBus.messages.EField; public final class MyAppAttributes extends EField { // Report when this application was released to production. public final ZonedDateTime releaseDate; // Text providing production release authorization. public final String releaseSignOff; // Application is running on this Java version. public final String javaVersion; // JVM implementation vendor. public final String javaVendor; // ... and any other attributes deemed necessary for // application support. }If monitor is already open, then returns the monitor singleton instance.
- Parameters:
host- monitor running on this "host". Does not necessary need to be a network host name.appName- the application name. May not benullor empty.version- the application version. May not benullor empty.copyright- the application copyright. May benull.description- the application description. May benull.attributes- the application-specific attributes. May benull.- Returns:
- singleton monitor instance.
- Throws:
java.lang.IllegalArgumentException- if eitherhost,nameorversionisnullor empty.
-
-