Class StubScheduler
- java.lang.Object
-
- com.google.gwt.core.client.Scheduler
-
- com.google.gwt.core.client.testing.StubScheduler
-
public class StubScheduler extends Scheduler
A fake scheduler that records scheduled commands and can execute them when asked to.Typical usage:
scheduleCommands(scheduler); assertFalse(scheduler.executeCommands());
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.gwt.core.client.Scheduler
Scheduler.RepeatingCommand, Scheduler.ScheduledCommand
-
-
Constructor Summary
Constructors Constructor Description StubScheduler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexecuteCommands()Executes all scheduled commands once.booleanexecuteRepeatingCommands()Executes all scheduledScheduler.RepeatingCommands once.booleanexecuteScheduledCommands()Executes all scheduledScheduler.ScheduledCommands that have been passed to this scheduler, then removes all commands.java.util.List<Scheduler.RepeatingCommand>getRepeatingCommands()Returns the currently scheduledScheduler.RepeatingCommands that would be executed byexecuteRepeatingCommands().java.util.List<Scheduler.ScheduledCommand>getScheduledCommands()Returns the currently scheduledScheduler.ScheduledCommands that would be executed byexecuteScheduledCommands().voidscheduleDeferred(Scheduler.ScheduledCommand cmd)A deferred command is executed after the browser event loop returns.voidscheduleEntry(Scheduler.RepeatingCommand cmd)An "entry" command will be executed before GWT-generated code is invoked by the browser's event loop.voidscheduleEntry(Scheduler.ScheduledCommand cmd)An "entry" command will be executed before GWT-generated code is invoked by the browser's event loop.voidscheduleFinally(Scheduler.RepeatingCommand cmd)A "finally" command will be executed before GWT-generated code returns control to the browser's event loop.voidscheduleFinally(Scheduler.ScheduledCommand cmd)A "finally" command will be executed before GWT-generated code returns control to the browser's event loop.voidscheduleFixedDelay(Scheduler.RepeatingCommand cmd, int delayMs)Schedules a repeating command that is scheduled with a constant delay.voidscheduleFixedPeriod(Scheduler.RepeatingCommand cmd, int delayMs)Schedules a repeating command that is scheduled with a constant periodicity.voidscheduleIncremental(Scheduler.RepeatingCommand cmd)Schedules a repeating command that performs incremental work.
-
-
-
Method Detail
-
getRepeatingCommands
public java.util.List<Scheduler.RepeatingCommand> getRepeatingCommands()
Returns the currently scheduledScheduler.RepeatingCommands that would be executed byexecuteRepeatingCommands().
-
executeCommands
public boolean executeCommands()
Executes all scheduled commands once. Equivalent to callingexecuteRepeatingCommands()thenexecuteScheduledCommands().Caveat: executes once any scheduled command created when executing the repeating commands.
- Returns:
- whether some repeating commands are still scheduled (returned
true) or new commands have been scheduled after the execution
-
executeRepeatingCommands
public boolean executeRepeatingCommands()
Executes all scheduledScheduler.RepeatingCommands once. Does not execute the commands newly scheduled by the initial commands. Removes the commands that returnedfalse.After this method completes,
getRepeatingCommands()returns only the commands that are still scheduled.- Returns:
- whether some commands are still scheduled (returned
true) or new commands have been scheduled after the execution
-
getScheduledCommands
public java.util.List<Scheduler.ScheduledCommand> getScheduledCommands()
Returns the currently scheduledScheduler.ScheduledCommands that would be executed byexecuteScheduledCommands().
-
executeScheduledCommands
public boolean executeScheduledCommands()
Executes all scheduledScheduler.ScheduledCommands that have been passed to this scheduler, then removes all commands.After this method completes,
getScheduledCommands()returns only the commands that have been scheduled by the initial commands.- Returns:
- whether new commands have been scheduled after the execution
-
scheduleDeferred
public void scheduleDeferred(Scheduler.ScheduledCommand cmd)
Description copied from class:SchedulerA deferred command is executed after the browser event loop returns.- Specified by:
scheduleDeferredin classScheduler
-
scheduleEntry
public void scheduleEntry(Scheduler.RepeatingCommand cmd)
Description copied from class:SchedulerAn "entry" command will be executed before GWT-generated code is invoked by the browser's event loop. TheScheduler.RepeatingCommandwill be called once per entry from the event loop untilfalseis returned. This type of command is appropriate for instrumentation or code that needs to know when "something happens."If an entry command schedules another entry command, the second command will be executed before control flow continues to the GWT-generated code.
- Specified by:
scheduleEntryin classScheduler
-
scheduleEntry
public void scheduleEntry(Scheduler.ScheduledCommand cmd)
Description copied from class:SchedulerAn "entry" command will be executed before GWT-generated code is invoked by the browser's event loop. This type of command is appropriate for code that needs to know when "something happens."If an entry command schedules another entry command, the second command will be executed before control flow continues to the GWT-generated code.
- Specified by:
scheduleEntryin classScheduler
-
scheduleFinally
public void scheduleFinally(Scheduler.RepeatingCommand cmd)
Description copied from class:SchedulerA "finally" command will be executed before GWT-generated code returns control to the browser's event loop. TheScheduler.RepeatingCommand.execute()method will be called once per exit to the event loop untilfalseis returned. This type of command is appropriate for instrumentation or cleanup code.If a finally command schedules another finally command, the second command will be executed before control flow returns to the browser.
- Specified by:
scheduleFinallyin classScheduler
-
scheduleFinally
public void scheduleFinally(Scheduler.ScheduledCommand cmd)
Description copied from class:SchedulerA "finally" command will be executed before GWT-generated code returns control to the browser's event loop. This type of command is used to aggregate small amounts of work before performing a non-recurring, heavyweight operation.If a finally command schedules another finally command, the second command will be executed before control flow returns to the browser.
Consider the following:
try { nativeEventCallback(); // Calls scheduleFinally one or more times } finally { executeFinallyCommands(); }- Specified by:
scheduleFinallyin classScheduler- See Also:
StyleInjector
-
scheduleFixedDelay
public void scheduleFixedDelay(Scheduler.RepeatingCommand cmd, int delayMs)
Description copied from class:SchedulerSchedules a repeating command that is scheduled with a constant delay. That is, the next invocation of the command will be scheduled fordelayMsmilliseconds after the last invocation completes.For example, assume that a command takes 30ms to run and a 100ms delay is provided. The second invocation of the command will occur at 130ms after the first invocation starts.
- Specified by:
scheduleFixedDelayin classScheduler- Parameters:
cmd- the command to executedelayMs- the amount of time to wait after one invocation ends before the next invocation
-
scheduleFixedPeriod
public void scheduleFixedPeriod(Scheduler.RepeatingCommand cmd, int delayMs)
Description copied from class:SchedulerSchedules a repeating command that is scheduled with a constant periodicity. That is, the command will be invoked everydelayMsmilliseconds, regardless of how long the previous invocation took to complete.- Specified by:
scheduleFixedPeriodin classScheduler- Parameters:
cmd- the command to executedelayMs- the period with which the command is executed
-
scheduleIncremental
public void scheduleIncremental(Scheduler.RepeatingCommand cmd)
Description copied from class:SchedulerSchedules a repeating command that performs incremental work. This type of command is encouraged for long-running processes that perform computation or that manipulate the DOM. The commands in this queue are invoked many times in rapid succession and are then deferred to allow the browser to process its event queue.- Specified by:
scheduleIncrementalin classScheduler- Parameters:
cmd- the command to execute
-
-