java.lang.Object
org.autogui.swing.util.SwingDeferredRunner
a task runner in the event dispatching thread without blocking
try {
Object ret = SwingDeferredRunner.run(task);
if (ret instanceof SwingDeferredRunner.TaskResultFuture
) {
Future<Object> f = ((TaskResultFuture) ret).getFuture();
...
} else {
...
}
} catch(Throwable errorWhileTask) { ... }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
a function interface under the event dispatching threadstatic class
a result for a thrown exception:SwingDeferredRunner.TaskResultFuture
return the value if the task failed with an exceptionstatic class
a incomplete result -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic ExecutorService
static ThreadLocal
<Boolean> protected Supplier
<ExecutorService> protected LinkedBlockingQueue
<Object> protected SwingDeferredRunner.Task
static Object
-
Constructor Summary
ConstructorsConstructorDescriptionSwingDeferredRunner
(Supplier<ExecutorService> futureFactory, SwingDeferredRunner.Task task) -
Method Summary
Modifier and TypeMethodDescriptionstatic void
static ExecutorService
static void
run the task bySwingUtilities.invokeAndWait(Runnable)
with wrapping byScheduledTaskRunner.withDepthInfo(String, Runnable)
andScheduledTaskRunner.depthRunner(Runnable)
static void
run the task bySwingUtilities.invokeLater(Runnable)
with wrapping byScheduledTaskRunner.depthRunner(Runnable)
static boolean
static boolean
run()
execute the specified task on the event dispatching thread and return the result.static Object
run
(SwingDeferredRunner.Task task)
-
Field Details
-
result
-
task
-
futureFactory
-
dispatchedFromEventThread
-
defaultService
-
TASK_RESULT_NULL
-
-
Constructor Details
-
SwingDeferredRunner
-
-
Method Details
-
isEventThreadOrDispatchedFromEventThread
public static boolean isEventThreadOrDispatchedFromEventThread() -
isDispatchedFromEventThread
public static boolean isDispatchedFromEventThread() -
invokeLater
run the task bySwingUtilities.invokeLater(Runnable)
with wrapping byScheduledTaskRunner.depthRunner(Runnable)
- Parameters:
r
- the task
-
invokeAndWait
run the task bySwingUtilities.invokeAndWait(Runnable)
with wrapping byScheduledTaskRunner.withDepthInfo(String, Runnable)
andScheduledTaskRunner.depthRunner(Runnable)
- Parameters:
r
- the task- Throws:
InterruptedException
- from invokeWaitInvocationTargetException
- from invokeWait
-
getDefaultService
-
cleanDefaultService
public static void cleanDefaultService() -
run
- Throws:
Throwable
-
run
execute the specified task on the event dispatching thread and return the result. if the current thread is the event dispatching thread, then it runs immediately. otherwise, submit the task to the event dispatching thread, and wait a little while and return a future value if it is not completed.- Returns:
- the result of the task (nullable) if no-delaying,
or
SwingDeferredRunner.TaskResultFuture
submitted to the futureFactory - Throws:
Throwable
- if the task throws an exception without delay, then it is thrown
-