java.lang.Object
org.autogui.base.mapping.ScheduledTaskRunner<EventType>
- Direct Known Subclasses:
EditingRunner
a delayed task executor accumulating subsequent firing events while the specified delay
ScheduledTaskRunner<E> r = new ScheduledTaskRunner<>(300, runner);
r.schedule(e1); //start a task with waiting 300 msec
r.schedule(e2); //cancel the previous task and start another new task with waiting 300 msec
sleep(300);
//the runner will be dispatched with a list of [e1, e2]
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classdebug features for task-running: the system-propertyorg.autogui.base.mapping.debugDepthcan beerr: specifies the output toSystem.err, or a file-path : specifies the output to the file.static classa task wrapper forScheduledTaskRunner.DepthStack -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longmsecprotected static ScheduledTaskRunner.DepthStacknon-null depth-stackprotected booleanprotected ScheduledExecutorServiceprotected booleantrue if theexecutorissharedExecutor.protected ScheduledFuture<?> static AtomicIntegerstatic ScheduledExecutorService -
Constructor Summary
ConstructorsConstructorDescriptionScheduledTaskRunner(long delay, Consumer<List<EventType>> consumer) creates a new task-runner withsharedExecutor.ScheduledTaskRunner(long delay, Consumer<List<EventType>> consumer, ScheduledExecutorService executor) -
Method Summary
Modifier and TypeMethodDescriptionstatic Runnablestatic <T> Callable<T> depthRunner(Callable<T> r) static <T> Supplier<T> depthRunner(Supplier<T> r) longgetDelay()static ScheduledExecutorServicevoidbooleanprotected booleanvoidrun()static voidrunForShared(Runnable task) execute a task with synchronization for handlingsharedExecutorvoidrunImmediately(EventType event) voidvoidifenabled, schedules a task for processing the event.voidsetConsumer(Consumer<List<EventType>> consumer) voidsetDelay(long delay) voidsetEnabled(boolean enabled) protected voidsetExecutor(ScheduledExecutorService executor) init the executor to the runner.voidshutdown()static voidwithDepthInfo(String info, Runnable body) static <T> TwithDepthInfo(String info, Callable<T> body)
-
Field Details
-
delay
protected long delaymsec -
executor
-
consumer
-
accumulatedEvents
-
scheduledTask
-
enabled
protected volatile boolean enabled -
depthStack
non-null depth-stack
-
-
Constructor Details
-
ScheduledTaskRunner
creates a new task-runner withsharedExecutor.- Parameters:
delay- the delay milliseconds for launching a taskconsumer- the actual task runner as taking accumulated events
-
ScheduledTaskRunner
public ScheduledTaskRunner(long delay, Consumer<List<EventType>> consumer, ScheduledExecutorService executor)
-
-
Method Details
-
initEnabled
protected boolean initEnabled() -
setExecutor
init the executor to the runner. if the executor issharedExecutor,executorIsSharedbecomes true. Basically the executor will not be changed, butshutdown()might cause renewal ofsharedExecutor. Thenschedule(Object, long)will call the method again for obtaining a newsharedExecutor.- Parameters:
executor- the executor to be set- Since:
- 1.2
-
getConsumer
-
setConsumer
-
getDelay
public long getDelay() -
setDelay
public void setDelay(long delay) -
schedule
-
schedule
ifenabled, schedules a task for processing the event. if another task is already scheduled, then the old task will be canceled. So, subsequent tasks cause extending the delayed time.If the
executorhave been shutdown and the executor is thesharedExecutor, then it will obtain a new shared executor bygetSharedExecutor(). This means the method causes reincarnation of the shared executor.- Parameters:
event- an accumulated event processed by a delayed taskdelayMSec- delaying milliseconds
-
withDepthInfo
- See Also:
-
withDepthInfo
- Throws:
Exception- See Also:
-
depthRunner
- See Also:
-
depthRunner
- See Also:
-
depthRunner
- See Also:
-
runImmediately
-
run
public void run() -
handleException
-
setEnabled
public void setEnabled(boolean enabled) -
getExecutor
-
shutdown
public void shutdown() -
hasScheduledTask
public boolean hasScheduledTask()- Returns:
- true if it has awaiting task
- Since:
- 1.3
-