Class DefaultNotificationReceiver

    • Field Detail

      • NOTIFICATION_INDEX_PROPERTY

        public static final java.lang.String NOTIFICATION_INDEX_PROPERTY
        Property referencing a notification index config section.
        See Also:
        Constant Field Values
      • INDEX_FILE_PROPERTY

        public static final java.lang.String INDEX_FILE_PROPERTY
        Shortcut to create a SQLite JDBCNotificationIndex.
        See Also:
        Constant Field Values
      • PRODUCT_STORAGE_PROPERTY

        public static final java.lang.String PRODUCT_STORAGE_PROPERTY
        Property referencing a product storage config section.
        See Also:
        Constant Field Values
      • STORAGE_DIRECTORY_PROPERTY

        public static final java.lang.String STORAGE_DIRECTORY_PROPERTY
        Shortcut to create a FileProductStorage.
        See Also:
        Constant Field Values
      • PRODUCT_STORAGE_MAX_AGE_PROPERTY

        public static final java.lang.String PRODUCT_STORAGE_MAX_AGE_PROPERTY
        Property referencing how long to store products in milliseconds.
        See Also:
        Constant Field Values
      • DEFAULT_PRODUCT_STORAGE_MAX_AGE

        public static final java.lang.String DEFAULT_PRODUCT_STORAGE_MAX_AGE
        Default max age to store products, 3600000 milliseconds = 1 hour.
        See Also:
        Constant Field Values
      • RECEIVER_CLEANUP_PROPERTY

        public static final java.lang.String RECEIVER_CLEANUP_PROPERTY
        Property referencing how long to wait until checking for expired notifications/products.
        See Also:
        Constant Field Values
      • DEFAULT_RECEIVER_CLEANUP

        public static final java.lang.String DEFAULT_RECEIVER_CLEANUP
        Default time between checking for expired notifications/products, 900000 milliseconds = 15 minutes.
        See Also:
        Constant Field Values
      • CONNECT_TIMEOUT_PROPERTY

        public static final java.lang.String CONNECT_TIMEOUT_PROPERTY
        Property for connection Timeout
        See Also:
        Constant Field Values
      • DEFAULT_CONNECT_TIMEOUT

        public static final java.lang.String DEFAULT_CONNECT_TIMEOUT
        Default connection timeout. 15 seconds
        See Also:
        Constant Field Values
      • READ_TIMEOUT_PROPERTY

        public static final java.lang.String READ_TIMEOUT_PROPERTY
        Property for read timeout
        See Also:
        Constant Field Values
      • DEFAULT_READ_TIMEOUT

        public static final java.lang.String DEFAULT_READ_TIMEOUT
        default read timeout. 15 seconds
        See Also:
        Constant Field Values
      • LISTENER_NOTIFIER_PROPERTY

        public static final java.lang.String LISTENER_NOTIFIER_PROPERTY
        Property for listener notifier
        See Also:
        Constant Field Values
      • EXECUTOR_LISTENER_NOTIFIER

        public static final java.lang.String EXECUTOR_LISTENER_NOTIFIER
        Property for listener notifier to set to executor
        See Also:
        Constant Field Values
      • FUTURE_LISTENER_NOTIFIER

        public static final java.lang.String FUTURE_LISTENER_NOTIFIER
        Property to listener notifier to set to future
        See Also:
        Constant Field Values
      • ROUNDROBIN_LISTENER_NOTIFIER

        public static final java.lang.String ROUNDROBIN_LISTENER_NOTIFIER
        Property to listener notifier to set to roundrobin
        See Also:
        Constant Field Values
    • Constructor Detail

      • DefaultNotificationReceiver

        public DefaultNotificationReceiver()
        Creates new ExecutorListenerNotifier to var notifier
    • Method Detail

      • addNotificationListener

        public void addNotificationListener​(NotificationListener listener)
                                     throws java.lang.Exception
        Add a new notification listener.
        Specified by:
        addNotificationListener in interface NotificationReceiver
        Parameters:
        listener - the listener to add. When notifications are received, this listener will be notified.
        Throws:
        java.lang.Exception - exception
      • removeNotificationListener

        public void removeNotificationListener​(NotificationListener listener)
                                        throws java.lang.Exception
        Remove an existing notification listener. Any currently queued notifications are processed before shutting down.
        Specified by:
        removeNotificationListener in interface NotificationReceiver
        Parameters:
        listener - the listener to remove. When notifications are receive, this listener will no longer be notified.
        Throws:
        java.lang.Exception - exception
      • receiveNotification

        public void receiveNotification​(Notification notification)
                                 throws java.lang.Exception
        Store a notification and notify listeners. Updates the notification index before notifying listeners of the newly available product.
        Specified by:
        receiveNotification in interface NotificationReceiver
        Parameters:
        notification - the notification being received.
        Throws:
        java.lang.Exception - if the notificationIndex throws an Exception.
      • notifyListeners

        protected void notifyListeners​(Notification notification)
                                throws java.lang.Exception
        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:
        java.lang.Exception - exception
      • getListenerQueueStatus

        public java.lang.String getListenerQueueStatus()
        Returns:
        "Using notifier"
      • removeExpiredNotifications

        public void removeExpiredNotifications()
                                        throws java.lang.Exception
        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 interface NotificationReceiver
        Throws:
        java.lang.Exception - if NotificationIndexCleanup throws an Exception.
      • onExpiredNotification

        public void onExpiredNotification​(Notification notification)
                                   throws java.lang.Exception
        Callback from the NotificationIndexCleanup thread. Checks if Notification refers to a product in storage, which should also be removed.
        Specified by:
        onExpiredNotification in interface NotificationIndexCleanup.Listener
        Parameters:
        notification - expired notification about to be removed.
        Throws:
        java.lang.Exception
      • retrieveProduct

        public Product retrieveProduct​(ProductId id)
                                throws java.lang.Exception
        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 interface NotificationReceiver
        Parameters:
        id - the product to retrieve
        Returns:
        the retrieved product, or null if not available.
        Throws:
        java.lang.Exception - exception
      • storeProductSource

        protected Notification storeProductSource​(ProductSource source)
                                           throws java.lang.Exception
        Calls the current ProductStorage.storeProductSource method.
        Parameters:
        source - The ProductSource to store.
        Returns:
        The ProductId of the product referenced by the given ProductSource.
        Throws:
        java.lang.Exception - exception
        See Also:
        ProductStorage
      • sendNotifications

        public void sendNotifications​(NotificationListener listener,
                                      java.util.List<java.lang.String> sources,
                                      java.util.List<java.lang.String> types,
                                      java.util.List<java.lang.String> codes)
                               throws java.lang.Exception
        Send matching notifications to listener. Searches the NotificationIndex for matching notifications, and sends a NotificationEvent for each notification found.
        Specified by:
        sendNotifications in interface NotificationReceiver
        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:
        java.lang.Exception - if the notification index or notification listener throw an exception.
      • configure

        public void configure​(Config config)
                       throws java.lang.Exception
        Description copied from class: DefaultConfigurable
        Process configuration settings. Called before startup().
        Specified by:
        configure in interface Configurable
        Overrides:
        configure in class DefaultConfigurable
        Parameters:
        config - the Config object with settings.
        Throws:
        java.lang.Exception - if configuration exceptions occur.
      • getNotificationIndex

        public NotificationIndex getNotificationIndex()
        Returns:
        the notificationIndex
      • setNotificationIndex

        public void setNotificationIndex​(NotificationIndex notificationIndex)
        Parameters:
        notificationIndex - the notificationIndex to set
      • getProductStorage

        public ProductStorage getProductStorage()
        Returns:
        the productStorage
      • setProductStorage

        public void setProductStorage​(ProductStorage productStorage)
        Parameters:
        productStorage - the productStorage to set
      • getProductStorageMaxAge

        public java.lang.Long getProductStorageMaxAge()
        Returns:
        the productStorageMaxAge
      • setProductStorageMaxAge

        public void setProductStorageMaxAge​(java.lang.Long productStorageMaxAge)
        Parameters:
        productStorageMaxAge - the productStorageMaxAge to set
      • getQueueStatus

        public java.util.Map<java.lang.String,​java.lang.Integer> getQueueStatus()
        Returns:
        the QueueStatus or null if ExecutorListenerNotifier doesn't exist
      • throttleQueues

        public void throttleQueues()
                            throws java.lang.InterruptedException
        Throttle notifier queues
        Throws:
        java.lang.InterruptedException - InterruptedException
      • getReceiverCleanupInterval

        public java.lang.Long getReceiverCleanupInterval()
        Returns:
        receiverCleanupInterval
      • setReceiverCleanupInterval

        public void setReceiverCleanupInterval​(java.lang.Long receiverCleanupInterval)
        Parameters:
        receiverCleanupInterval - the receiverCleanupInterval to set
      • getConnectTimeout

        public int getConnectTimeout()
        Returns:
        connectionTimeout
      • setConnectTimeout

        public void setConnectTimeout​(int connectTimeout)
        Parameters:
        connectTimeout - int connectionTimeout to set
      • setNotifier

        public void setNotifier​(ListenerNotifier notifier)
        Parameters:
        notifier - ListenerNotifier to set
      • getReadTimeout

        public int getReadTimeout()
        Returns:
        readTimeout
      • setReadTimeout

        public void setReadTimeout​(int readTimeout)
        Parameters:
        readTimeout - int readTimeout to set