Package gov.usgs.earthquake.distribution
Class HeartbeatListener
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.product.AbstractListener
gov.usgs.earthquake.distribution.DefaultNotificationListener
gov.usgs.earthquake.distribution.HeartbeatListener
- All Implemented Interfaces:
NotificationIndexCleanup.Listener,NotificationListener,Configurable
Heartbeat Listener stores heartbeat messages and writes them to a heartbeat
file when a product is received
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault schedule interval for HeartbeatStatus key/value pairs cleanup.static final StringDefault heartbeat directory.static final StringDefault timeout for HeartbeatStatus key/value pairs.static final StringConfigurable property for heartbeat fully qualified directory+filename.static final StringConfigurable property for heartbeat key/value expirationFields inherited from class gov.usgs.earthquake.distribution.DefaultNotificationListener
CLEANUP_INTERVAL_PROPERTY, CONCURRENT_PRODUCTS_PROPERTY, DEFAULT_CONCURRENT_PRODUCTS, DEFAULT_PROCESS_DUPLICATES, EXCLUDE_PATHS_PROPERTY, INCLUDE_PATHS_PROPERTY, INDEX_FILE_PROPERTY, NOTIFICATION_INDEX_PROPERTY, PROCESS_DUPLICATESFields inherited from class gov.usgs.earthquake.product.AbstractListener
ATTEMPT_COUNT_PROPERTY, DEFAULT_ATTEMPT_COUNT, DEFAULT_RETRY_DELAY, DEFAULT_TIMEOUT, EXCLUDE_SOURCES_PROPERTY, EXCLUDE_TYPES_PROPERTY, INCLUDE_ACTUALS_PROPERTY, INCLUDE_DEVELOPMENTS_PROPERTY, INCLUDE_INTERNALS_PROPERTY, INCLUDE_SCENARIOS_PROPERTY, INCLUDE_SOURCES_PROPERTY, INCLUDE_TESTS_PROPERTY, INCLUDE_TYPES_PROPERTY, MAX_TRIES_PROPERTY, RETRY_DELAY_PROPERTY, TIMEOUT_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()purge heartbeat key/values older than storageTimeout, also purging empty heartbeatsvoidSelf-configure HeartbeatListener objectprotected static Map<String,HeartbeatStatus> longvoidheartbeat onProduct processing writes to heartbeat filestatic voidsendHeartbeatMessage(String component, String key, String value) Send heartbeat data to heartbeat listenervoidsetHeartbeatFile(File heartbeatFile) voidsetStorageTimeout(long storageTimeout) booleanWrite heartbeat data for all components to the heartbeat fileMethods inherited from class gov.usgs.earthquake.distribution.DefaultNotificationListener
getCleanupInterval, getConcurrentProducts, getExcludePaths, getIncludePaths, getNotificationIndex, isProcessDuplicates, onAfterProcessNotification, onBeforeProcessNotification, onBeforeProcessProduct, onExpiredNotification, onNotification, setCleanupInterval, setConcurrentProducts, setNotificationIndex, setProcessDuplicates, shutdown, startupMethods inherited from class gov.usgs.earthquake.product.AbstractListener
accept, getExcludeSources, getExcludeTypes, getIncludeSources, getIncludeTypes, getMaxTries, getRetryDelay, getTimeout, isIncludeActuals, isIncludeDevelopments, isIncludeInternals, isIncludeScenarios, isIncludeTests, setIncludeActuals, setIncludeDevelopments, setIncludeInternals, setIncludeScenarios, setIncludeTests, setMaxTries, setRetryDelay, setTimeoutMethods inherited from class gov.usgs.util.DefaultConfigurable
getName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface gov.usgs.util.Configurable
getName, setNameMethods inherited from interface gov.usgs.earthquake.distribution.NotificationListener
getMaxTries, getTimeout
-
Field Details
-
HEARTBEAT_FILENAME_PROPERTY
Configurable property for heartbeat fully qualified directory+filename.- See Also:
-
DEFAULT_HEARTBEAT_FILENAME
Default heartbeat directory.- See Also:
-
DEFAULT_STORAGE_TIMEOUT
Default timeout for HeartbeatStatus key/value pairs. Zero = disabled- See Also:
-
DEFAULT_CLEANUP_INTERVAL
Default schedule interval for HeartbeatStatus key/value pairs cleanup. 30 minutes- See Also:
-
HEARTBEAT_TIMEOUT_PROPERTY
Configurable property for heartbeat key/value expiration- See Also:
-
-
Constructor Details
-
HeartbeatListener
Create a new HeartbeatListener. Sets up the includeTypes list to contain "heartbeat".- Throws:
Exception- if error occurs
-
-
Method Details
-
getHeartbeats
- Returns:
- map of component and heartbeat status.
-
onProduct
heartbeat onProduct processing writes to heartbeat file- Overrides:
onProductin classDefaultNotificationListener- Parameters:
product- a product whose notification was accepted.- Throws:
Exception- if error occurs
-
sendHeartbeatMessage
Send heartbeat data to heartbeat listener- Parameters:
component- String componentkey- Heartbeat keyvalue- Heartbeat value
-
writeHeartbeat
Write heartbeat data for all components to the heartbeat file- Returns:
- true
- Throws:
IOException- if IO error occurs
-
configure
Self-configure HeartbeatListener object- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classDefaultNotificationListener- Parameters:
config- the Config object with settings.- Throws:
Exception- if configuration exceptions occur.
-
formatHeartbeatOutput
- Returns:
- JSON-formatted output from the map of components and their values
-
cleanup
purge heartbeat key/values older than storageTimeout, also purging empty heartbeats- Overrides:
cleanupin classDefaultNotificationListener- Throws:
Exception- if could not create new notificationCleanup
-
getHeartbeatFile
- Returns:
- heartbeatFile
-
setHeartbeatFile
- Parameters:
heartbeatFile- to set
-
getStorageTimeout
public long getStorageTimeout()- Returns:
- storageTimeout
-
setStorageTimeout
public void setStorageTimeout(long storageTimeout) - Parameters:
storageTimeout- to set
-