Top Description Inners Fields Constructors Methods
rx.schedulers

public Class TestScheduler

extends Scheduler
Class Inheritance
Imports
java.util.Comparator, .PriorityQueue, .Queue, java.util.concurrent.TimeUnit, rx.Scheduler, .Subscription, rx.functions.Action0, rx.internal.schedulers.SchedulePeriodicHelper, .SchedulePeriodicHelper.NowNanoSupplier, rx.subscriptions.BooleanSubscription, .Subscriptions

The TestScheduler is useful for debugging. It allows you to test schedules of events by manually advancing the clock at whatever pace you choose.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv class
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static long
pack-priv final Queue<TestScheduler.TimedAction>
pack-priv long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
advanceTimeBy(long
the amount of time to move the Scheduler's clock forward
delayTime
,
TimeUnit
the units of time that delayTime is expressed in
unit
)

Moves the Scheduler's clock forward by a specified amount of time.

public void
advanceTimeTo(long
the point in time to move the Scheduler's clock to
delayTime
,
TimeUnit
the units of time that delayTime is expressed in
unit
)

Moves the Scheduler's clock to a particular moment in time.

public Scheduler.Worker
createWorker()

Implements abstract rx.Scheduler.createWorker.

Retrieves or creates a new Scheduler.Worker that represents serial execution of actions.
public long
now()

Overrides rx.Scheduler.now.

Gets the current time, in milliseconds, according to this Scheduler.
public void
triggerActions()

Triggers any actions that have not yet been triggered and that are scheduled to be triggered at or before this Scheduler's present time.

private void
triggerActions(long targetTimeInNanos)

Inherited from rx.Scheduler:
when

Field Detail

counterback to summary
pack-priv static long counter
queueback to summary
pack-priv final Queue<TestScheduler.TimedAction> queue
timeback to summary
pack-priv long time

Constructor Detail

TestSchedulerback to summary
public TestScheduler()

Method Detail

advanceTimeByback to summary
public void advanceTimeBy(long delayTime, TimeUnit unit)

Moves the Scheduler's clock forward by a specified amount of time.

Parameters
delayTime:long

the amount of time to move the Scheduler's clock forward

unit:TimeUnit

the units of time that delayTime is expressed in

advanceTimeToback to summary
public void advanceTimeTo(long delayTime, TimeUnit unit)

Moves the Scheduler's clock to a particular moment in time.

Parameters
delayTime:long

the point in time to move the Scheduler's clock to

unit:TimeUnit

the units of time that delayTime is expressed in

createWorkerback to summary
public Scheduler.Worker createWorker()

Implements abstract rx.Scheduler.createWorker.

Doc from rx.Scheduler.createWorker.

Retrieves or creates a new Scheduler.Worker that represents serial execution of actions.

When work is completed it should be unsubscribed using Scheduler.Worker#unsubscribe().

Work on a Scheduler.Worker is guaranteed to be sequential.

Returns:Scheduler.Worker

a Worker representing a serial queue of actions to be executed

Annotations
@Override
nowback to summary
public long now()

Overrides rx.Scheduler.now.

Doc from rx.Scheduler.now.

Gets the current time, in milliseconds, according to this Scheduler.

Returns:long

the scheduler's notion of current absolute time in milliseconds

Annotations
@Override
triggerActionsback to summary
public void triggerActions()

Triggers any actions that have not yet been triggered and that are scheduled to be triggered at or before this Scheduler's present time.

triggerActionsback to summary
private void triggerActions(long targetTimeInNanos)
rx.schedulers back to summary

pack-priv final Class TestScheduler.CompareActionsByTime

extends Object
implements Comparator<TestScheduler.TimedAction>
Class Inheritance
All Implemented Interfaces
java.util.Comparator

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
compare(TestScheduler.TimedAction
the first object to be compared.
action1
,
TestScheduler.TimedAction
the second object to be compared.
action2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CompareActionsByTimeback to summary
pack-priv CompareActionsByTime()

Method Detail

compareback to summary
public int compare(TestScheduler.TimedAction action1, TestScheduler.TimedAction action2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
action1:TestScheduler.TimedAction

the first object to be compared.

action2:TestScheduler.TimedAction

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
rx.schedulers back to summary

pack-priv final Class TestScheduler.InnerTestScheduler

extends Worker
implements NowNanoSupplier
Class Inheritance
All Implemented Interfaces
rx.internal.schedulers.SchedulePeriodicHelper.NowNanoSupplier

Field Summary

Modifier and TypeField and Description
private final BooleanSubscription
s

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.
public long
now()

Overrides rx.Scheduler.Worker.now.

Gets the current time, in milliseconds, according to this Scheduler.
public long
public Subscription
schedule(Action0
the Action to schedule
action
,
long
time to wait before executing the action; non-positive values indicate an non-delayed schedule
delayTime
,
TimeUnit
the time unit of delayTime
unit
)

Implements abstract rx.Scheduler.Worker.schedule.

Schedules an Action for execution at some point in the future.
public Subscription
schedule(Action0
Action to schedule
action
)

Implements abstract rx.Scheduler.Worker.schedule.

Schedules an Action for execution.
public Subscription
schedulePeriodically(Action0
the Action to execute periodically
action
,
long
time to wait before executing the action for the first time; non-positive values indicate an non-delayed schedule
initialDelay
,
long
the time interval to wait each time in between executing the action; non-positive values indicate no delay between repeated schedules
period
,
TimeUnit
the time unit of period
unit
)

Overrides rx.Scheduler.Worker.schedulePeriodically.

Schedules a cancelable action to be executed periodically.
public void
unsubscribe()

Implements rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

Field Detail

sback to summary
private final BooleanSubscription s

Constructor Detail

InnerTestSchedulerback to summary
pack-priv InnerTestScheduler()

Method Detail

isUnsubscribedback to summary
public boolean isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Doc from rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.

Returns:boolean

true if this Subscription is currently unsubscribed, false otherwise

Annotations
@Override
nowback to summary
public long now()

Overrides rx.Scheduler.Worker.now.

Doc from rx.Scheduler.Worker.now.

Gets the current time, in milliseconds, according to this Scheduler.

Returns:long

the scheduler's notion of current absolute time in milliseconds

Annotations
@Override
nowNanosback to summary
public long nowNanos()

Implements rx.internal.schedulers.SchedulePeriodicHelper.NowNanoSupplier.nowNanos.

Annotations
@Override
scheduleback to summary
public Subscription schedule(Action0 action, long delayTime, TimeUnit unit)

Implements abstract rx.Scheduler.Worker.schedule.

Doc from rx.Scheduler.Worker.schedule.

Schedules an Action for execution at some point in the future.

Note to implementors: non-positive delayTime should be regarded as non-delayed schedule, i.e., as if the schedule(rx.functions.Action0) was called.

Parameters
action:Action0

the Action to schedule

delayTime:long

time to wait before executing the action; non-positive values indicate an non-delayed schedule

unit:TimeUnit

the time unit of delayTime

Returns:Subscription

a subscription to be able to prevent or cancel the execution of the action

Annotations
@Override
scheduleback to summary
public Subscription schedule(Action0 action)

Implements abstract rx.Scheduler.Worker.schedule.

Doc from rx.Scheduler.Worker.schedule.

Schedules an Action for execution.

Parameters
action:Action0

Action to schedule

Returns:Subscription

a subscription to be able to prevent or cancel the execution of the action

Annotations
@Override
schedulePeriodicallyback to summary
public Subscription schedulePeriodically(Action0 action, long initialDelay, long period, TimeUnit unit)

Overrides rx.Scheduler.Worker.schedulePeriodically.

Doc from rx.Scheduler.Worker.schedulePeriodically.

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.

Note to implementors: non-positive initialTime and period should be regarded as non-delayed scheduling of the first and any subsequent executions.

Parameters
action:Action0

the Action to execute periodically

initialDelay:long

time to wait before executing the action for the first time; non-positive values indicate an non-delayed schedule

period:long

the time interval to wait each time in between executing the action; non-positive values indicate no delay between repeated schedules

unit:TimeUnit

the time unit of period

Returns:Subscription

a subscription to be able to prevent or cancel the execution of the action

Annotations
@Override
unsubscribeback to summary
public void unsubscribe()

Implements rx.Subscription.unsubscribe.

Doc from rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

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

Annotations
@Override
rx.schedulers back to summary

pack-priv final Class TestScheduler.TimedAction

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Action0
private final long
pack-priv final Scheduler.Worker
pack-priv final long

Constructor Summary

AccessConstructor and Description
pack-priv
TimedAction(Scheduler.Worker scheduler, long time, Action0 action)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

actionback to summary
pack-priv final Action0 action
countback to summary
private final long count
schedulerback to summary
pack-priv final Scheduler.Worker scheduler
timeback to summary
pack-priv final long time

Constructor Detail

TimedActionback to summary
pack-priv TimedAction(Scheduler.Worker scheduler, long time, Action0 action)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override