Class ExecutorListenerNotifier

    • Field Detail

      • notificationListeners

        protected java.util.Map<NotificationListener,​java.util.concurrent.ExecutorService> notificationListeners
        Notification listeners registered to receive notifications, and an ExecutorService that delivers Notifications to each in a separate thread.
      • acceptBeforeQueuing

        protected boolean acceptBeforeQueuing
        Make sure listener will accept notification before queueing it for processing.
      • retryTimer

        protected java.util.Timer retryTimer
        Timer used to retry tasks when they fail and listeners have configured retryDelay.
      • throttleStartThreshold

        protected int throttleStartThreshold
        When queue size reaches this level, start throttling
      • throttleStopThreshold

        protected int throttleStopThreshold
        When queue size reaches this level, stop throttling
      • throttleWaitInterval

        protected long throttleWaitInterval
        When throttling, wait this many milliseconds between queue size checks.
    • Constructor Detail

      • ExecutorListenerNotifier

        public ExecutorListenerNotifier​(DefaultNotificationReceiver receiver)
        Constructor
        Parameters:
        receiver - DefaultNotificationReceiver
    • Method Detail

      • addNotificationListener

        public void addNotificationListener​(NotificationListener listener)
                                     throws java.lang.Exception
        Add a new notification listener.
        Specified by:
        addNotificationListener in interface ListenerNotifier
        Parameters:
        listener - the listener to add. When notifications are received, this listener will be notified.
        Throws:
        java.lang.Exception - if error occurs
      • 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 ListenerNotifier
        Parameters:
        listener - the listener to remove. When notifications are receive, this listener will no longer be notified.
        Throws:
        java.lang.Exception - if error occurs
      • notifyListeners

        public void notifyListeners​(NotificationEvent event)
                             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.
        Specified by:
        notifyListeners in interface ListenerNotifier
        Parameters:
        event - the notification being sent to listeners.
        Throws:
        java.lang.Exception - if error occurs
      • notifyListeners

        public void notifyListeners​(NotificationEvent event,
                                    java.util.Collection<NotificationListener> listeners)
                             throws java.lang.Exception
        Calls queueNotification with event and listener for each listener
        Parameters:
        event - NotificationEvent
        listeners - Collection of NotificationListeners
        Throws:
        java.lang.Exception - if error occurs
      • queueNotification

        protected void queueNotification​(NotificationListener listener,
                                         NotificationEvent event)
        Parameters:
        listener - NotificationListener
        event - NotificationEvent
      • setReceiver

        public void setReceiver​(DefaultNotificationReceiver receiver)
        Parameters:
        receiver - of the default notification variety
      • getStatus

        public java.util.Map<java.lang.String,​java.lang.Integer> getStatus()
        Returns:
        map of status
      • getMaxQueueSize

        public java.lang.Integer getMaxQueueSize()
        Check queue status and return length of longest queue.
        Returns:
        length of longest queue, or null if no queue lengths.
      • throttleQueues

        public void throttleQueues()
                            throws java.lang.InterruptedException
        If longest queue has more than 50k notifications, wait until longest queue has 25k notifications before returning.
        Throws:
        java.lang.InterruptedException - if error occurs
      • throttleQueues

        public void throttleQueues​(java.lang.Integer remaining)
                            throws java.lang.InterruptedException
        If longest queue has more than 50k notifications, wait until longest queue has 25k notifications before returning.
        Parameters:
        remaining - integer
        Throws:
        java.lang.InterruptedException - if error occurs
      • getExecutors

        public java.util.Map<NotificationListener,​java.util.concurrent.ExecutorService> getExecutors()
        NOTE: messing with the executors map is not a good idea.
        Returns:
        the map of listeners and their executors.
      • getThrottleStartThreshold

        public int getThrottleStartThreshold()
        Returns:
        int throttle start threshold
      • setThrottleStartThreshold

        public void setThrottleStartThreshold​(int n)
        Parameters:
        n - int throttle start threshold
      • getThrottleStopThreshold

        public int getThrottleStopThreshold()
        Returns:
        int throttle stop threshold
      • setThrottleStopThreshold

        public void setThrottleStopThreshold​(int n)
        Parameters:
        n - int throttle stop threshold
      • getThrottleWaitInterval

        public long getThrottleWaitInterval()
        Returns:
        int throttle wait interval
      • setThrottleWaitInterval

        public void setThrottleWaitInterval​(long ms)
        Parameters:
        ms - long throttle wait interval in ms