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
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_TRACKING_FILE_NAME_PROPERTYName of deafult tracking filestatic java.lang.StringDEFAULT_UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTYDefault state of update after exceptionstatic java.lang.StringSEQUENCE_PROPERTYProperty for sequencestatic java.lang.StringTRACKING_FILE_NAME_PROPERTYProperty for tracking file namestatic java.lang.StringUPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTYProperty on if update sequence should occur after exception-
Fields 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 Constructor Description NATSStreamingNotificationReceiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(Config config)Configures receiver based on included propertiesNATSClientgetClient()java.lang.StringgetSubject()java.lang.StringgetTrackingFileName()voidonMessage(io.nats.streaming.Message message)Defines behavior for message receipt.javax.json.JsonObjectreadTrackingFile()Reads contents of tracking filevoidsetClient(NATSClient client)voidsetSubject(java.lang.String subject)voidsetTrackingFileName(java.lang.String trackingFileName)voidshutdown()Closes subscription/connection and writes state in tracking file Wraps each statement in a try/catch to ensure each step still happensvoidstartup()Does initial tracking file management and subscribes to server With a tracking file, gets the last sequencevoidwriteTrackingFile()Writes pertinent configuration information to tracking file-
Methods 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 Detail
-
TRACKING_FILE_NAME_PROPERTY
public static java.lang.String TRACKING_FILE_NAME_PROPERTY
Property for tracking file name
-
UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
public static java.lang.String UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
Property on if update sequence should occur after exception
-
SEQUENCE_PROPERTY
public static java.lang.String SEQUENCE_PROPERTY
Property for sequence
-
DEFAULT_TRACKING_FILE_NAME_PROPERTY
public static java.lang.String DEFAULT_TRACKING_FILE_NAME_PROPERTY
Name of deafult tracking file
-
DEFAULT_UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
public static java.lang.String DEFAULT_UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
Default state of update after exception
-
-
Method Detail
-
configure
public void configure(Config config) throws java.lang.Exception
Configures receiver based on included properties- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classDefaultNotificationReceiver- Parameters:
config- The user-defined configuration- Throws:
java.lang.Exception- If required properties are ignored
-
startup
public void startup() throws java.lang.ExceptionDoes initial tracking file management and subscribes to server With a tracking file, gets the last sequence- Specified by:
startupin interfaceConfigurable- Overrides:
startupin classDefaultNotificationReceiver- Throws:
java.lang.InterruptedException- if interruptedjava.io.IOException- if IO error occursjava.lang.Exception- if exceptions occur while starting.
-
shutdown
public void shutdown() throws java.lang.ExceptionCloses subscription/connection and writes state in tracking file Wraps each statement in a try/catch to ensure each step still happens- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin classDefaultNotificationReceiver- Throws:
java.io.IOException- if IO error occursjava.lang.InterruptedException- if interruptedjava.util.concurrent.TimeoutException- if timeoutjava.lang.Exception- if exceptions occur while starting.
-
writeTrackingFile
public void writeTrackingFile() throws java.lang.ExceptionWrites pertinent configuration information to tracking file- Throws:
java.lang.Exception- if error occurs
-
readTrackingFile
public javax.json.JsonObject readTrackingFile() throws java.lang.ExceptionReads contents of tracking file- Returns:
- JsonObject containing tracking file contents, or null if file doesn't exist
- Throws:
java.lang.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:
onMessagein interfaceio.nats.streaming.MessageHandler- Parameters:
message- The message received from the STAN server
-
getTrackingFileName
public java.lang.String getTrackingFileName()
- Returns:
- trackingFileName
-
setTrackingFileName
public void setTrackingFileName(java.lang.String trackingFileName)
- Parameters:
trackingFileName- to set
-
getClient
public NATSClient getClient()
- Returns:
- NATSClient
-
setClient
public void setClient(NATSClient client)
- Parameters:
client- NATSClient to set
-
getSubject
public java.lang.String getSubject()
- Returns:
- subject
-
setSubject
public void setSubject(java.lang.String subject)
- Parameters:
subject- to set
-
-