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 String
Default schedule interval for HeartbeatStatus key/value pairs cleanup.static final String
Default heartbeat directory.static final String
Default timeout for HeartbeatStatus key/value pairs.static final String
Configurable property for heartbeat fully qualified directory+filename.static final String
Configurable 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_DUPLICATES
Fields 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 TypeMethodDescriptionvoid
cleanup()
purge heartbeat key/values older than storageTimeout, also purging empty heartbeatsvoid
Self-configure HeartbeatListener objectprotected static Map<String,
HeartbeatStatus> long
void
heartbeat onProduct processing writes to heartbeat filestatic void
sendHeartbeatMessage
(String component, String key, String value) Send heartbeat data to heartbeat listenervoid
setHeartbeatFile
(File heartbeatFile) void
setStorageTimeout
(long storageTimeout) boolean
Write 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, startup
Methods 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, setTimeout
Methods inherited from class gov.usgs.util.DefaultConfigurable
getName, setName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface gov.usgs.util.Configurable
getName, setName
Methods 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:
onProduct
in 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:
configure
in interfaceConfigurable
- Overrides:
configure
in 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:
cleanup
in 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
-