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.String
DEFAULT_TRACKING_FILE_NAME_PROPERTY
Name of deafult tracking filestatic java.lang.String
DEFAULT_UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
Default state of update after exceptionstatic java.lang.String
SEQUENCE_PROPERTY
Property for sequencestatic java.lang.String
TRACKING_FILE_NAME_PROPERTY
Property for tracking file namestatic java.lang.String
UPDATE_SEQUENCE_AFTER_EXCEPTION_PROPERTY
Property 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 void
configure(Config config)
Configures receiver based on included propertiesNATSClient
getClient()
java.lang.String
getSubject()
java.lang.String
getTrackingFileName()
void
onMessage(io.nats.streaming.Message message)
Defines behavior for message receipt.javax.json.JsonObject
readTrackingFile()
Reads contents of tracking filevoid
setClient(NATSClient client)
void
setSubject(java.lang.String subject)
void
setTrackingFileName(java.lang.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
writeTrackingFile()
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:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultNotificationReceiver
- Parameters:
config
- The user-defined configuration- Throws:
java.lang.Exception
- If required properties are ignored
-
startup
public void startup() throws java.lang.Exception
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:
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.Exception
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:
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.Exception
Writes pertinent configuration information to tracking file- Throws:
java.lang.Exception
- if error occurs
-
readTrackingFile
public javax.json.JsonObject readTrackingFile() throws java.lang.Exception
Reads 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:
onMessage
in 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
-
-