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,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 StringProperty for connection Timeoutstatic final StringDefault connection timeout.static final StringDefault max age to store products, 3600000 milliseconds = 1 hour.static final Stringdefault read timeout.static final StringDefault time between checking for expired notifications/products, 900000 milliseconds = 15 minutes.static final StringProperty for listener notifier to set to executorstatic final StringProperty to listener notifier to set to futurestatic final StringShortcut to create a SQLite JDBCNotificationIndex.static final StringProperty for listener notifierstatic final StringProperty referencing a notification index config section.static final StringProperty referencing how long to store products in milliseconds.static final StringProperty referencing a product storage config section.static final StringProperty for read timeoutstatic final StringProperty referencing how long to wait until checking for expired notifications/products.static final StringProperty to listener notifier to set to roundrobinstatic final StringShortcut to create a FileProductStorage. -
Constructor Summary
ConstructorsConstructorDescriptionCreates new ExecutorListenerNotifier to var notifier -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNotificationListener(NotificationListener listener) Add a new notification listener.voidProcess configuration settings.intintprotected voidnotifyListeners(Notification notification) Send a notification to all registered NotificationListeners.voidonExpiredNotification(Notification notification) Callback from the NotificationIndexCleanup thread.voidreceiveNotification(Notification notification) Store a notification and notify listeners.voidSearch the notification index for expired notifications, removing any that are found.voidRemove an existing notification listener.Retrieve a product by id.voidsendNotifications(NotificationListener listener, List<String> sources, List<String> types, List<String> codes) Send matching notifications to listener.voidsetConnectTimeout(int connectTimeout) voidsetNotificationIndex(NotificationIndex notificationIndex) voidsetNotifier(ListenerNotifier notifier) voidsetProductStorage(ProductStorage productStorage) voidsetProductStorageMaxAge(Long productStorageMaxAge) voidsetReadTimeout(int readTimeout) voidsetReceiverCleanupInterval(Long receiverCleanupInterval) voidshutdown()Stop any processing/background threads.voidstartup()Start any processing/background threads.protected NotificationstoreProductSource(ProductSource source) Calls the currentProductStorage.storeProductSourcemethod.voidThrottle notifier queuesMethods inherited from class gov.usgs.util.DefaultConfigurable
getName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
addNotificationListenerin 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:
removeNotificationListenerin 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:
receiveNotificationin 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:
removeExpiredNotificationsin 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:
onExpiredNotificationin 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:
retrieveProductin interfaceNotificationReceiver- Parameters:
id- the product to retrieve- Returns:
- the retrieved product, or null if not available.
- Throws:
Exception- exception
-
storeProductSource
Calls the currentProductStorage.storeProductSourcemethod.- Parameters:
source- TheProductSourceto store.- Returns:
- The
ProductIdof 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:
sendNotificationsin 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:DefaultConfigurableProcess configuration settings. Called before startup().- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classDefaultConfigurable- Parameters:
config- the Config object with settings.- Throws:
Exception- if configuration exceptions occur.
-
shutdown
Description copied from class:DefaultConfigurableStop any processing/background threads.- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin classDefaultConfigurable- Throws:
Exception- if exceptions occur while starting.
-
startup
Description copied from class:DefaultConfigurableStart any processing/background threads.- Specified by:
startupin interfaceConfigurable- Overrides:
startupin 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
-