java.lang.Object
org.autogui.swing.GuiSwingTaskRunner
a task runner for deferring a task takes long time to complete.
basically, the methods of GuiRepresentation need to be executed
under the thread of the task runner of
GuiMappingContext.getTaskRunner()
.
executeContextTask(Supplier, Consumer)
achieves this.
new GuiSwingTaskRunner(context).executeContextTask( () -> context.getReprValue().getUpdatedValue(context, spec), r -> r.executeIfPresented(v -> SwingUtilities.invokeLater(() -> setSwingViewValue(v))))
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
a base class for actionsstatic class
the returned value for successfully obtaining a valuestatic class
a task failure by delaystatic class
the failure status of execution with an exceptionstatic class
delayed result -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<RetType> GuiSwingTaskRunner.ContextTaskResult
<RetType> executeContextTask
(boolean useTaskRunner, Supplier<RetType> task, Consumer<GuiSwingTaskRunner.ContextTaskResult<RetType>> afterTask) executeContextTask(Supplier, Consumer)
with additional flag for task-runner: the method is used for custom checking of the runner submission like collection-table: the context of the runner is not the actual context of the task.<RetType> GuiSwingTaskRunner.ContextTaskResult
<RetType> executeContextTask
(Supplier<RetType> task, Consumer<GuiSwingTaskRunner.ContextTaskResult<RetType>> afterTask) run task on the task-runner of the context (GuiMappingContext.getTaskRunner()
).static <RetType> GuiSwingTaskRunner.ContextTaskResult
<RetType> executeContextTaskWithContext
(Supplier<RetType> task, Consumer<GuiSwingTaskRunner.ContextTaskResult<RetType>> afterTask) <RetType> GuiSwingTaskRunner.ContextTaskResultFail
<RetType> fail
(boolean timeout, Consumer<GuiSwingTaskRunner.ContextTaskResult<RetType>> afterTask)
-
Field Details
-
context
-
-
Constructor Details
-
GuiSwingTaskRunner
-
-
Method Details
-
getContext
-
executeContextTask
public <RetType> GuiSwingTaskRunner.ContextTaskResult<RetType> executeContextTask(Supplier<RetType> task, Consumer<GuiSwingTaskRunner.ContextTaskResult<RetType>> afterTask) run task on the task-runner of the context (GuiMappingContext.getTaskRunner()
).- if the task takes a long time to complete,
the method will return with
GuiSwingTaskRunner.ContextTaskResult.isTimeout()
==true, and start to wait the completion of the task on a thread ofSwingDeferredRunner.getDefaultService()
. - if the task causes an
InterruptedException
, the method will returns withGuiSwingTaskRunner.ContextTaskResult.isCancel()
==true. - After the completion, afterTask will be executed.
-
The afterTask also be executed when a timeout or an interruption happens:
after the timeout task completion, the afterTask will be executed again
with returned value wrapped by a result value with
GuiSwingTaskRunner.ContextTaskResult.isPresentedWithDelay()
==true.-
While waiting after timeout, the user may click the cancel button of the task.
This may cause an
InterruptedException
and then the afterTask is executed withGuiSwingTaskRunner.ContextTaskResult.isCancel()
==true
-
While waiting after timeout, the user may click the cancel button of the task.
This may cause an
-
In most cases, the method is executed from the event-dispatching thread.
Thus, the task should not use
SwingUtilities.invokeAndWait(Runnable)
. To check the condition, useSwingDeferredRunner.isEventThreadOrDispatchedFromEventThread()
. The method turns on the flagSwingDeferredRunner.dispatchedFromEventThread
while running the task.
- Type Parameters:
RetType
- the value type of the task- Parameters:
task
- the executed task.afterTask
- a task executed after the task. nullable- Returns:
- the result status of the task: cancel, timeout or returned
- if the task takes a long time to complete,
the method will return with
-
executeContextTask
public <RetType> GuiSwingTaskRunner.ContextTaskResult<RetType> executeContextTask(boolean useTaskRunner, Supplier<RetType> task, Consumer<GuiSwingTaskRunner.ContextTaskResult<RetType>> afterTask) executeContextTask(Supplier, Consumer)
with additional flag for task-runner: the method is used for custom checking of the runner submission like collection-table: the context of the runner is not the actual context of the task.- Type Parameters:
RetType
- the value type of the task- Parameters:
useTaskRunner
- if false, it will be executed byexecuteContextTaskWithContext(Supplier, Consumer)
task
- the running taskafterTask
- a task executed after the task. nullable: if null, the method might cause an exception. otherwise, the consumer becomes a finally-block.- Returns:
- the result status of the task: cancel, timeout or returned
- Since:
- 1.6
-
fail
public <RetType> GuiSwingTaskRunner.ContextTaskResultFail<RetType> fail(boolean timeout, Consumer<GuiSwingTaskRunner.ContextTaskResult<RetType>> afterTask) -
getFutureWaiter
-
executeContextTaskWithContext
public static <RetType> GuiSwingTaskRunner.ContextTaskResult<RetType> executeContextTaskWithContext(Supplier<RetType> task, Consumer<GuiSwingTaskRunner.ContextTaskResult<RetType>> afterTask)
-