RxJava



rx
Class Scheduler

java.lang.Object
  extended by rx.Scheduler
Direct Known Subclasses:
CurrentThreadScheduler, ExecutorScheduler, ImmediateScheduler, NewThreadScheduler, TestScheduler

public abstract class Scheduler
extends java.lang.Object

Represents an object that schedules units of work.

The methods left to implement are:

Why is this an abstract class instead of an interface?

  1. Java doesn't support extension methods and there are many overload methods needing default implementations.
  2. Virtual extension methods aren't available until Java8 which RxJava will not set as a minimum target for a long time.
  3. If only an interface were used Scheduler implementations would then need to extend from an AbstractScheduler pair that gives all of the functionality unless they intend on copy/pasting the functionality.
  4. Without virtual extension methods even additive changes are breaking and thus severely impede library maintenance.


Constructor Summary
Scheduler()
           
 
Method Summary
 long now()
          Returns the scheduler's notion of current absolute time in milliseconds.
 Subscription schedule(Action0 action)
          Schedules an action to be executed.
 Subscription schedule(Action0 action, long delayTime, java.util.concurrent.TimeUnit unit)
          Schedules an action to be executed in delayTime.
abstract
<T> Subscription
schedule(T state, Func2<? super Scheduler,? super T,? extends Subscription> action)
          Schedules a cancelable action to be executed.
<T> Subscription
schedule(T state, Func2<? super Scheduler,? super T,? extends Subscription> action, java.util.Date dueTime)
          Schedules a cancelable action to be executed at dueTime.
abstract
<T> Subscription
schedule(T state, Func2<? super Scheduler,? super T,? extends Subscription> action, long delayTime, java.util.concurrent.TimeUnit unit)
          Schedules a cancelable action to be executed in delayTime.
 Subscription schedulePeriodically(Action0 action, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
          Schedules an action to be executed periodically.
<T> Subscription
schedulePeriodically(T state, Func2<? super Scheduler,? super T,? extends Subscription> action, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
          Schedules a cancelable action to be executed periodically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scheduler

public Scheduler()
Method Detail

schedule

public abstract <T> Subscription schedule(T state,
                                          Func2<? super Scheduler,? super T,? extends Subscription> action)
Schedules a cancelable action to be executed.

Parameters:
state - State to pass into the action.
action - Action to schedule.
Returns:
a subscription to be able to unsubscribe from action.

schedule

public abstract <T> Subscription schedule(T state,
                                          Func2<? super Scheduler,? super T,? extends Subscription> action,
                                          long delayTime,
                                          java.util.concurrent.TimeUnit unit)
Schedules a cancelable action to be executed in delayTime.

Parameters:
state - State to pass into the action.
action - Action to schedule.
delayTime - Time the action is to be delayed before executing.
unit - Time unit of the delay time.
Returns:
a subscription to be able to unsubscribe from action.

schedulePeriodically

public <T> Subscription schedulePeriodically(T state,
                                             Func2<? super Scheduler,? super T,? extends Subscription> action,
                                             long initialDelay,
                                             long period,
                                             java.util.concurrent.TimeUnit unit)
Schedules a cancelable action to be executed periodically. This default implementation schedules recursively and waits for actions to complete (instead of potentially executing long-running actions concurrently). Each scheduler that can do periodic scheduling in a better way should override this.

Parameters:
state - State to pass into the action.
action - The action to execute periodically.
initialDelay - Time to wait before executing the action for the first time.
period - The time interval to wait each time in between executing the action.
unit - The time unit the interval above is given in.
Returns:
A subscription to be able to unsubscribe from action.

schedule

public <T> Subscription schedule(T state,
                                 Func2<? super Scheduler,? super T,? extends Subscription> action,
                                 java.util.Date dueTime)
Schedules a cancelable action to be executed at dueTime.

Parameters:
state - State to pass into the action.
action - Action to schedule.
dueTime - Time the action is to be executed. If in the past it will be executed immediately.
Returns:
a subscription to be able to unsubscribe from action.

schedule

public Subscription schedule(Action0 action)
Schedules an action to be executed.

Parameters:
action - action
Returns:
a subscription to be able to unsubscribe from action.

schedule

public Subscription schedule(Action0 action,
                             long delayTime,
                             java.util.concurrent.TimeUnit unit)
Schedules an action to be executed in delayTime.

Parameters:
action - action
Returns:
a subscription to be able to unsubscribe from action.

schedulePeriodically

public Subscription schedulePeriodically(Action0 action,
                                         long initialDelay,
                                         long period,
                                         java.util.concurrent.TimeUnit unit)
Schedules an action to be executed periodically.

Parameters:
action - The action to execute periodically.
initialDelay - Time to wait before executing the action for the first time.
period - The time interval to wait each time in between executing the action.
unit - The time unit the interval above is given in.
Returns:
A subscription to be able to unsubscribe from action.

now

public long now()
Returns the scheduler's notion of current absolute time in milliseconds.