Package gov.usgs.earthquake.nats
Class NATSStreamingNotificationReceiver
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.distribution.DefaultNotificationReceiver
gov.usgs.earthquake.nats.NATSStreamingNotificationReceiver
- All Implemented Interfaces:
NotificationIndexCleanup.Listener
,NotificationReceiver
,Configurable
,io.nats.streaming.MessageHandler
public class NATSStreamingNotificationReceiver
extends DefaultNotificationReceiver
implements io.nats.streaming.MessageHandler
Connects directly to a NATS streaming server to receive notifications using a
NATSClient
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic String
Name of deafult tracking filestatic String
Default state of update after exceptionstatic String
Property for sequencestatic String
Property for tracking file namestatic String
Property on if update sequence should occur after exceptionFields inherited from class gov.usgs.earthquake.distribution.DefaultNotificationReceiver
CONNECT_TIMEOUT_PROPERTY, DEFAULT_CONNECT_TIMEOUT, DEFAULT_PRODUCT_STORAGE_MAX_AGE, DEFAULT_READ_TIMEOUT, DEFAULT_RECEIVER_CLEANUP, EXECUTOR_LISTENER_NOTIFIER, FUTURE_LISTENER_NOTIFIER, INDEX_FILE_PROPERTY, LISTENER_NOTIFIER_PROPERTY, NOTIFICATION_INDEX_PROPERTY, PRODUCT_STORAGE_MAX_AGE_PROPERTY, PRODUCT_STORAGE_PROPERTY, READ_TIMEOUT_PROPERTY, RECEIVER_CLEANUP_PROPERTY, ROUNDROBIN_LISTENER_NOTIFIER, STORAGE_DIRECTORY_PROPERTY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Configures receiver based on included propertiesvoid
onMessage
(io.nats.streaming.Message message) Defines behavior for message receipt.javax.json.JsonObject
Reads contents of tracking filevoid
setClient
(NATSClient client) void
setSubject
(String subject) void
setTrackingFileName
(String trackingFileName) void
shutdown()
Closes subscription/connection and writes state in tracking file Wraps each statement in a try/catch to ensure each step still happensvoid
startup()
Does initial tracking file management and subscribes to server With a tracking file, gets the last sequencevoid
Writes pertinent configuration information to tracking fileMethods inherited from class gov.usgs.earthquake.distribution.DefaultNotificationReceiver
addNotificationListener, getConnectTimeout, getListenerQueueStatus, getNotificationIndex, getNotifier, getProductStorage, getProductStorageMaxAge, getQueueStatus, getReadTimeout, getReceiverCleanupInterval, notifyListeners, onExpiredNotification, receiveNotification, removeExpiredNotifications, removeNotificationListener, retrieveProduct, sendNotifications, setConnectTimeout, setNotificationIndex, setNotifier, setProductStorage, setProductStorageMaxAge, setReadTimeout, setReceiverCleanupInterval, storeProductSource, throttleQueues
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
-
Field Details
-
TRACKING_FILE_NAME_PROPERTY
Property for tracking file name -
UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
Property on if update sequence should occur after exception -
SEQUENCE_PROPERTY
Property for sequence -
DEFAULT_TRACKING_FILE_NAME_PROPERTY
Name of deafult tracking file -
DEFAULT_UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
Default state of update after exception
-
-
Constructor Details
-
NATSStreamingNotificationReceiver
public NATSStreamingNotificationReceiver()
-
-
Method Details
-
configure
Configures receiver based on included properties- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultNotificationReceiver
- Parameters:
config
- The user-defined configuration- Throws:
Exception
- If required properties are ignored
-
startup
Does initial tracking file management and subscribes to server With a tracking file, gets the last sequence- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultNotificationReceiver
- Throws:
InterruptedException
- if interruptedIOException
- if IO error occursException
- if exceptions occur while starting.
-
shutdown
Closes subscription/connection and writes state in tracking file Wraps each statement in a try/catch to ensure each step still happens- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultNotificationReceiver
- Throws:
IOException
- if IO error occursInterruptedException
- if interruptedTimeoutException
- if timeoutException
- if exceptions occur while starting.
-
writeTrackingFile
Writes pertinent configuration information to tracking file- Throws:
Exception
- if error occurs
-
readTrackingFile
Reads contents of tracking file- Returns:
- JsonObject containing tracking file contents, or null if file doesn't exist
- Throws:
Exception
- if error occurs
-
onMessage
public void onMessage(io.nats.streaming.Message message) Defines behavior for message receipt. Attempts to process notifications, with configurable behavior for exception handling- Specified by:
onMessage
in interfaceio.nats.streaming.MessageHandler
- Parameters:
message
- The message received from the STAN server
-
getTrackingFileName
- Returns:
- trackingFileName
-
setTrackingFileName
- Parameters:
trackingFileName
- to set
-
getClient
- Returns:
- NATSClient
-
setClient
- Parameters:
client
- NATSClient to set
-
getSubject
- Returns:
- subject
-
setSubject
- Parameters:
subject
- to set
-