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
public class HeartbeatListener extends DefaultNotificationListener
Heartbeat Listener stores heartbeat messages and writes them to a heartbeat file when a product is received
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_CLEANUP_INTERVAL
Default schedule interval for HeartbeatStatus key/value pairs cleanup.static java.lang.String
DEFAULT_HEARTBEAT_FILENAME
Default heartbeat directory.static java.lang.String
DEFAULT_STORAGE_TIMEOUT
Default timeout for HeartbeatStatus key/value pairs.static java.lang.String
HEARTBEAT_FILENAME_PROPERTY
Configurable property for heartbeat fully qualified directory+filename.static java.lang.String
HEARTBEAT_TIMEOUT_PROPERTY
Configurable property for heartbeat key/value expiration-
Fields 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 Constructor Description HeartbeatListener()
Create a new HeartbeatListener.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanup()
purge heartbeat key/values older than storageTimeout, also purging empty heartbeatsvoid
configure(Config config)
Self-configure HeartbeatListener objectjava.lang.String
formatHeartbeatOutput()
java.io.File
getHeartbeatFile()
protected static java.util.Map<java.lang.String,HeartbeatStatus>
getHeartbeats()
long
getStorageTimeout()
void
onProduct(Product product)
heartbeat onProduct processing writes to heartbeat filestatic void
sendHeartbeatMessage(java.lang.String component, java.lang.String key, java.lang.String value)
Send heartbeat data to heartbeat listenervoid
setHeartbeatFile(java.io.File heartbeatFile)
void
setStorageTimeout(long storageTimeout)
boolean
writeHeartbeat()
Write heartbeat data for all components to the heartbeat file-
Methods 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 Detail
-
HEARTBEAT_FILENAME_PROPERTY
public static final java.lang.String HEARTBEAT_FILENAME_PROPERTY
Configurable property for heartbeat fully qualified directory+filename.- See Also:
- Constant Field Values
-
DEFAULT_HEARTBEAT_FILENAME
public static final java.lang.String DEFAULT_HEARTBEAT_FILENAME
Default heartbeat directory.- See Also:
- Constant Field Values
-
DEFAULT_STORAGE_TIMEOUT
public static final java.lang.String DEFAULT_STORAGE_TIMEOUT
Default timeout for HeartbeatStatus key/value pairs. Zero = disabled- See Also:
- Constant Field Values
-
DEFAULT_CLEANUP_INTERVAL
public static final java.lang.String DEFAULT_CLEANUP_INTERVAL
Default schedule interval for HeartbeatStatus key/value pairs cleanup. 30 minutes- See Also:
- Constant Field Values
-
HEARTBEAT_TIMEOUT_PROPERTY
public static final java.lang.String HEARTBEAT_TIMEOUT_PROPERTY
Configurable property for heartbeat key/value expiration- See Also:
- Constant Field Values
-
-
Method Detail
-
getHeartbeats
protected static java.util.Map<java.lang.String,HeartbeatStatus> getHeartbeats()
- Returns:
- map of component and heartbeat status.
-
onProduct
public void onProduct(Product product) throws java.lang.Exception
heartbeat onProduct processing writes to heartbeat file- Overrides:
onProduct
in classDefaultNotificationListener
- Parameters:
product
- a product whose notification was accepted.- Throws:
java.lang.Exception
- if error occurs
-
sendHeartbeatMessage
public static void sendHeartbeatMessage(java.lang.String component, java.lang.String key, java.lang.String value)
Send heartbeat data to heartbeat listener- Parameters:
component
- String componentkey
- Heartbeat keyvalue
- Heartbeat value
-
writeHeartbeat
public boolean writeHeartbeat() throws java.io.IOException
Write heartbeat data for all components to the heartbeat file- Returns:
- true
- Throws:
java.io.IOException
- if IO error occurs
-
configure
public void configure(Config config) throws java.lang.Exception
Self-configure HeartbeatListener object- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultNotificationListener
- Parameters:
config
- the Config object with settings.- Throws:
java.lang.Exception
- if configuration exceptions occur.
-
formatHeartbeatOutput
public java.lang.String formatHeartbeatOutput()
- Returns:
- JSON-formatted output from the map of components and their values
-
cleanup
public void cleanup() throws java.lang.Exception
purge heartbeat key/values older than storageTimeout, also purging empty heartbeats- Overrides:
cleanup
in classDefaultNotificationListener
- Throws:
java.lang.Exception
-
getHeartbeatFile
public java.io.File getHeartbeatFile()
- Returns:
- heartbeatFile
-
setHeartbeatFile
public void setHeartbeatFile(java.io.File heartbeatFile)
- Parameters:
heartbeatFile
- to set
-
getStorageTimeout
public long getStorageTimeout()
- Returns:
- storageTimeout
-
setStorageTimeout
public void setStorageTimeout(long storageTimeout)
- Parameters:
storageTimeout
- to set
-
-