Class ScheduledAction

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Runnable, Subscription

    public final class ScheduledAction
    extends java.util.concurrent.atomic.AtomicReference<java.lang.Thread>
    implements java.lang.Runnable, Subscription
    A Runnable that executes an Action0 and can be cancelled. The analog is the Subscriber in respect of an Observer.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  ScheduledAction.FutureCompleter
      Cancels the captured future if the caller of the call method is not the same as the runner of the outer ScheduledAction to prevent unnecessary self-interrupting if the unsubscription happens from the same thread.
      (package private) static class  ScheduledAction.Remover
      Remove a child subscription from a composite when unsubscribing.
      (package private) static class  ScheduledAction.Remover2
      Remove a child subscription from a composite when unsubscribing.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.util.concurrent.Future<?> f)
      Adds the given Future to the unsubscription composite in order to support cancelling the underlying task in the executor framework.
      void add​(Subscription s)
      Adds a general Subscription to this ScheduledAction that will be unsubscribed if the underlying action completes or the this scheduled action is cancelled.
      void addParent​(SubscriptionList parent)
      Adds a parent CompositeSubscription to this ScheduledAction so when the action is cancelled or terminates, it can remove itself from this parent.
      void addParent​(CompositeSubscription parent)
      Adds a parent CompositeSubscription to this ScheduledAction so when the action is cancelled or terminates, it can remove itself from this parent.
      boolean isUnsubscribed()
      Indicates whether this Subscription is currently unsubscribed.
      void run()  
      (package private) void signalError​(java.lang.Throwable ie)  
      void unsubscribe()
      Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.
      • Methods inherited from class java.util.concurrent.atomic.AtomicReference

        accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, lazySet, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • signalError

        void signalError​(java.lang.Throwable ie)
      • isUnsubscribed

        public boolean isUnsubscribed()
        Description copied from interface: Subscription
        Indicates whether this Subscription is currently unsubscribed.
        Specified by:
        isUnsubscribed in interface Subscription
        Returns:
        true if this Subscription is currently unsubscribed, false otherwise
      • unsubscribe

        public void unsubscribe()
        Description copied from interface: Subscription
        Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

        This allows unregistering an Subscriber before it has finished receiving all events (i.e. before onCompleted is called).

        Specified by:
        unsubscribe in interface Subscription
      • add

        public void add​(Subscription s)
        Adds a general Subscription to this ScheduledAction that will be unsubscribed if the underlying action completes or the this scheduled action is cancelled.
        Parameters:
        s - the Subscription to add
      • add

        public void add​(java.util.concurrent.Future<?> f)
        Adds the given Future to the unsubscription composite in order to support cancelling the underlying task in the executor framework.
        Parameters:
        f - the future to add
      • addParent

        public void addParent​(CompositeSubscription parent)
        Adds a parent CompositeSubscription to this ScheduledAction so when the action is cancelled or terminates, it can remove itself from this parent.
        Parameters:
        parent - the parent CompositeSubscription to add
      • addParent

        public void addParent​(SubscriptionList parent)
        Adds a parent CompositeSubscription to this ScheduledAction so when the action is cancelled or terminates, it can remove itself from this parent.
        Parameters:
        parent - the parent CompositeSubscription to add