Package gov.usgs.earthquake.distribution
Class DefaultNotificationReceiver
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.distribution.DefaultNotificationReceiver
- All Implemented Interfaces:
NotificationIndexCleanup.Listener
,NotificationReceiver
,Configurable
- Direct Known Subclasses:
AwsProductReceiver
,EIDSNotificationReceiver
,NATSStreamingNotificationReceiver
,SocketProductReceiver
,WebSocketNotificationReceiver
public class DefaultNotificationReceiver
extends DefaultConfigurable
implements NotificationReceiver, NotificationIndexCleanup.Listener
The core of product distribution.
A DefaultNotificationReceiver receives notifications and notifies listeners
of received notifications. NotificationListeners use the NotificationReceiver
to retrieve products referenced by notifications.
The NotificationReceiver uses a NotificationIndex to track received
notifications, and a ProductStorage to store retrieved products.
The DefaultNotificationReceiver implements the Configurable interface and
uses the following configuration parameters:
Each listener has a separate queue of notifications. Each listener is
allocated one thread to process notifications from this queue.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Property for connection Timeoutstatic final String
Default connection timeout.static final String
Default max age to store products, 3600000 milliseconds = 1 hour.static final String
default read timeout.static final String
Default time between checking for expired notifications/products, 900000 milliseconds = 15 minutes.static final String
Property for listener notifier to set to executorstatic final String
Property to listener notifier to set to futurestatic final String
Shortcut to create a SQLite JDBCNotificationIndex.static final String
Property for listener notifierstatic final String
Property referencing a notification index config section.static final String
Property referencing how long to store products in milliseconds.static final String
Property referencing a product storage config section.static final String
Property for read timeoutstatic final String
Property referencing how long to wait until checking for expired notifications/products.static final String
Property to listener notifier to set to roundrobinstatic final String
Shortcut to create a FileProductStorage. -
Constructor Summary
ConstructorsConstructorDescriptionCreates new ExecutorListenerNotifier to var notifier -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNotificationListener
(NotificationListener listener) Add a new notification listener.void
Process configuration settings.int
int
protected void
notifyListeners
(Notification notification) Send a notification to all registered NotificationListeners.void
onExpiredNotification
(Notification notification) Callback from the NotificationIndexCleanup thread.void
receiveNotification
(Notification notification) Store a notification and notify listeners.void
Search the notification index for expired notifications, removing any that are found.void
Remove an existing notification listener.Retrieve a product by id.void
sendNotifications
(NotificationListener listener, List<String> sources, List<String> types, List<String> codes) Send matching notifications to listener.void
setConnectTimeout
(int connectTimeout) void
setNotificationIndex
(NotificationIndex notificationIndex) void
setNotifier
(ListenerNotifier notifier) void
setProductStorage
(ProductStorage productStorage) void
setProductStorageMaxAge
(Long productStorageMaxAge) void
setReadTimeout
(int readTimeout) void
setReceiverCleanupInterval
(Long receiverCleanupInterval) void
shutdown()
Stop any processing/background threads.void
startup()
Start any processing/background threads.protected Notification
storeProductSource
(ProductSource source) Calls the currentProductStorage.storeProductSource
method.void
Throttle notifier queuesMethods 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
-
NOTIFICATION_INDEX_PROPERTY
Property referencing a notification index config section.- See Also:
-
INDEX_FILE_PROPERTY
Shortcut to create a SQLite JDBCNotificationIndex.- See Also:
-
PRODUCT_STORAGE_PROPERTY
Property referencing a product storage config section.- See Also:
-
STORAGE_DIRECTORY_PROPERTY
Shortcut to create a FileProductStorage.- See Also:
-
PRODUCT_STORAGE_MAX_AGE_PROPERTY
Property referencing how long to store products in milliseconds.- See Also:
-
DEFAULT_PRODUCT_STORAGE_MAX_AGE
Default max age to store products, 3600000 milliseconds = 1 hour.- See Also:
-
RECEIVER_CLEANUP_PROPERTY
Property referencing how long to wait until checking for expired notifications/products.- See Also:
-
DEFAULT_RECEIVER_CLEANUP
Default time between checking for expired notifications/products, 900000 milliseconds = 15 minutes.- See Also:
-
CONNECT_TIMEOUT_PROPERTY
Property for connection Timeout- See Also:
-
DEFAULT_CONNECT_TIMEOUT
Default connection timeout. 15 seconds- See Also:
-
READ_TIMEOUT_PROPERTY
Property for read timeout- See Also:
-
DEFAULT_READ_TIMEOUT
default read timeout. 15 seconds- See Also:
-
LISTENER_NOTIFIER_PROPERTY
Property for listener notifier- See Also:
-
EXECUTOR_LISTENER_NOTIFIER
Property for listener notifier to set to executor- See Also:
-
FUTURE_LISTENER_NOTIFIER
Property to listener notifier to set to future- See Also:
-
ROUNDROBIN_LISTENER_NOTIFIER
Property to listener notifier to set to roundrobin- See Also:
-
-
Constructor Details
-
DefaultNotificationReceiver
public DefaultNotificationReceiver()Creates new ExecutorListenerNotifier to var notifier
-
-
Method Details
-
addNotificationListener
Add a new notification listener.- Specified by:
addNotificationListener
in interfaceNotificationReceiver
- Parameters:
listener
- the listener to add. When notifications are received, this listener will be notified.- Throws:
Exception
- exception
-
removeNotificationListener
Remove an existing notification listener. Any currently queued notifications are processed before shutting down.- Specified by:
removeNotificationListener
in interfaceNotificationReceiver
- Parameters:
listener
- the listener to remove. When notifications are receive, this listener will no longer be notified.- Throws:
Exception
- exception
-
receiveNotification
Store a notification and notify listeners. Updates the notification index before notifying listeners of the newly available product.- Specified by:
receiveNotification
in interfaceNotificationReceiver
- Parameters:
notification
- the notification being received.- Throws:
Exception
- if the notificationIndex throws an Exception.
-
notifyListeners
Send a notification to all registered NotificationListeners. Creates a NotificationEvent, with a reference to this object and calls each notificationListeners onNotification method in separate threads. This method usually returns before registered NotificationListeners have completed processing a notification.- Parameters:
notification
- the notification being sent to listeners.- Throws:
Exception
- exception
-
getListenerQueueStatus
- Returns:
- "Using notifier"
-
removeExpiredNotifications
Search the notification index for expired notifications, removing any that are found. When a notification in the index is not a URLNotification, it represents a product in storage that will also be removed.- Specified by:
removeExpiredNotifications
in interfaceNotificationReceiver
- Throws:
Exception
- if NotificationIndexCleanup throws an Exception.
-
onExpiredNotification
Callback from the NotificationIndexCleanup thread. Checks if Notification refers to a product in storage, which should also be removed.- Specified by:
onExpiredNotification
in interfaceNotificationIndexCleanup.Listener
- Parameters:
notification
- expired notification about to be removed.- Throws:
Exception
- if error occurs sttempting to removing product- See Also:
-
retrieveProduct
Retrieve a product by id. If this product is already in storage, load and return the product. Otherwise, search notifications for this product, and download the product into storage.- Specified by:
retrieveProduct
in interfaceNotificationReceiver
- Parameters:
id
- the product to retrieve- Returns:
- the retrieved product, or null if not available.
- Throws:
Exception
- exception
-
storeProductSource
Calls the currentProductStorage.storeProductSource
method.- Parameters:
source
- TheProductSource
to store.- Returns:
- The
ProductId
of the product referenced by the givenProductSource
. - Throws:
Exception
- See Also:
-
sendNotifications
public void sendNotifications(NotificationListener listener, List<String> sources, List<String> types, List<String> codes) throws Exception Send matching notifications to listener. Searches the NotificationIndex for matching notifications, and sends a NotificationEvent for each notification found.- Specified by:
sendNotifications
in interfaceNotificationReceiver
- Parameters:
listener
- the listener to receive a NotificationEvent for each found notification.sources
- sources to include, or null for all.types
- types to include, or null for all.codes
- codes to include, or null for all.- Throws:
Exception
- if the notification index or notification listener throw an exception.
-
configure
Description copied from class:DefaultConfigurable
Process configuration settings. Called before startup().- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultConfigurable
- Parameters:
config
- the Config object with settings.- Throws:
Exception
- if configuration exceptions occur.
-
shutdown
Description copied from class:DefaultConfigurable
Stop any processing/background threads.- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultConfigurable
- Throws:
Exception
- if exceptions occur while starting.
-
startup
Description copied from class:DefaultConfigurable
Start any processing/background threads.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultConfigurable
- Throws:
Exception
- if exceptions occur while starting.
-
getNotificationIndex
- Returns:
- the notificationIndex
-
setNotificationIndex
- Parameters:
notificationIndex
- the notificationIndex to set
-
getProductStorage
- Returns:
- the productStorage
-
setProductStorage
- Parameters:
productStorage
- the productStorage to set
-
getProductStorageMaxAge
- Returns:
- the productStorageMaxAge
-
setProductStorageMaxAge
- Parameters:
productStorageMaxAge
- the productStorageMaxAge to set
-
getQueueStatus
- Returns:
- the QueueStatus or null if ExecutorListenerNotifier doesn't exist
-
throttleQueues
Throttle notifier queues- Throws:
InterruptedException
- InterruptedException
-
getReceiverCleanupInterval
- Returns:
- receiverCleanupInterval
-
setReceiverCleanupInterval
- Parameters:
receiverCleanupInterval
- the receiverCleanupInterval to set
-
getConnectTimeout
public int getConnectTimeout()- Returns:
- connectionTimeout
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout) - Parameters:
connectTimeout
- int connectionTimeout to set
-
getNotifier
- Returns:
- ListenerNotifier
-
setNotifier
- Parameters:
notifier
- ListenerNotifier to set
-
getReadTimeout
public int getReadTimeout()- Returns:
- readTimeout
-
setReadTimeout
public void setReadTimeout(int readTimeout) - Parameters:
readTimeout
- int readTimeout to set
-