Class AbstractEthosNotificationSubscription

  • All Implemented Interfaces:
    Flow.Subscription
    Direct Known Subclasses:
    AbstractEthosChangeNotificationSubscription

    public abstract class AbstractEthosNotificationSubscription
    extends Object
    implements Flow.Subscription
    An abstract super class for Ethos subscriptions containing the publisher, subscriber, and the threading capabilities used by subscription subclasses to run those subscription processes.

    Subscriptions will run indefinitely until canceled. The cancel() method must be called to stop the subscription from running.

    Implements the Flow.Subscription interface.

    Since:
    0.2.0
    Author:
    David Kumar
    • Field Detail

      • publisher

        protected Flow.Publisher publisher
        The publisher of this subscription.
      • subscriber

        protected Flow.Subscriber subscriber
        The subscriber subscribing to this subscription.
      • cancelSubscription

        protected AtomicBoolean cancelSubscription
        Used to manage cancellation requests for cancelling the thread running this subscription.
      • scheduledExecutorService

        protected ScheduledExecutorService scheduledExecutorService
        Runs the thread for this subscription on a polling interval schedule.
      • scheduledFuture

        protected ScheduledFuture scheduledFuture
        Assigned by the scheduledExecutorService when it schedules the subscription process to run.
      • pollingInterval

        protected long pollingInterval
        The amount of time to wait between polls. A single poll will process all notifications from Ethos Integration. Subsequent polls will then process further notifications as they are available.
      • pollingIntervalTimeUnit

        protected TimeUnit pollingIntervalTimeUnit
        The time unit for the polling interval. Commonly specified by the publisher as TimeUnit.SECONDS.
    • Constructor Detail

      • AbstractEthosNotificationSubscription

        public AbstractEthosNotificationSubscription​(Flow.Publisher publisher,
                                                     Flow.Subscriber subscriber,
                                                     long pollingInterval,
                                                     TimeUnit pollingIntervalTimeUnit)
        Super constructor which must be called by subclasses supplying the given params. If the given pollingIntervalTimeUnit is null, it defaults to TimeUnit.SECONDS.
        Parameters:
        publisher - The publisher for this subscription.
        subscriber - The subscriber subscribing to this subscription.
        pollingInterval - The polling interval between poll attempts.
        pollingIntervalTimeUnit - The time unit for polling intervals.
        Throws:
        IllegalArgumentException - Thrown if the given publisher or subscriber is null.
    • Method Detail

      • request

        public void request​(long numNotifications)
        Intended to be used internally by the SDK.

        Should be overridden by subscription subclasses in the SDK.

        Specified by:
        request in interface Flow.Subscription
        Parameters:
        numNotifications - Indicates some number of notifications to process.
      • cancel

        public void cancel()
        Sets the cancellation flag to true, thereby requesting that the subscription stop running after the current polling operation completes. Subscriptions will run indefinitely, so this method must be called to stop them from running.
        Specified by:
        cancel in interface Flow.Subscription
      • isRunning

        public boolean isRunning()
        Indicates if this subscription is still running, or not.
        Returns:
        true if this subscription is running, in which case a subscriber would be subscribed to it and be receiving notifications (if any are retrieved), false if this subscription has been canceled.