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 class
debug features for task-running: the system-propertyorg.autogui.base.mapping.debugDepth
can beerr
: specifies the output toSystem.err
, or a file-path : specifies the output to the file.static class
a task wrapper forScheduledTaskRunner.DepthStack
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected long
msecprotected static ScheduledTaskRunner.DepthStack
non-null depth-stackprotected boolean
protected ScheduledExecutorService
protected boolean
true if theexecutor
issharedExecutor
.protected ScheduledFuture
<?> static AtomicInteger
static 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 Runnable
static <T> Callable
<T> depthRunner
(Callable<T> r) static <T> Supplier
<T> depthRunner
(Supplier<T> r) long
getDelay()
static ScheduledExecutorService
void
boolean
protected boolean
void
run()
static void
runForShared
(Runnable task) execute a task with synchronization for handlingsharedExecutor
void
runImmediately
(EventType event) void
void
ifenabled
, schedules a task for processing the event.void
setConsumer
(Consumer<List<EventType>> consumer) void
setDelay
(long delay) void
setEnabled
(boolean enabled) protected void
setExecutor
(ScheduledExecutorService executor) init the executor to the runner.void
shutdown()
static void
withDepthInfo
(String info, Runnable body) static <T> T
withDepthInfo
(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
,executorIsShared
becomes 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
executor
have 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
-