Top Description Fields Constructors Methods
org.jabref.gui.util

public Class UiTaskExecutor

extends Object
implements TaskExecutor
Class Inheritance
All Implemented Interfaces
org.jabref.gui.util.TaskExecutor
Imports
java.util.Objects, .WeakHashMap, java.util.concurrent.Callable, .CountDownLatch, .ExecutionException, .ExecutorService, .Executors, .Future, .FutureTask, .ScheduledExecutorService, .TimeUnit, java.util.function.Consumer, javafx.application.Platform, javafx.concurrent.Task, org.jabref.gui.StateManager, org.jabref.logic.util.DelayTaskThrottler, .HeadlessExecutorService, com.airhacks.afterburner.injection.Injector, org.slf4j.Logger, .LoggerFactory

A very simple implementation of the TaskExecutor interface. Every submitted task is invoked in a separate thread.

In case something does not interact well with JavaFX, you can use the HeadlessExecutorService

Field Summary

Modifier and TypeField and Description
private final ExecutorService
private static final Logger
private final ScheduledExecutorService
private final WeakHashMap<DelayTaskThrottler, Void>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private Exception
public DelayTaskThrottler
createThrottler(int delay)

Implements org.jabref.gui.util.TaskExecutor.createThrottler.

Creates a new task throttler, and registers it so that it gets properly shutdown.

public <V> Future<V>
execute(BackgroundTask<V>
the task to run
task
)

Implements org.jabref.gui.util.TaskExecutor.execute.

Runs the given task and returns a Future representing that task.

public <V> Future<V>
execute(Task<V>
the task to run
task
)

Implements org.jabref.gui.util.TaskExecutor.execute.

Runs the given task and returns a Future representing that task.

private <V> Task<V>

Returns:

a new Task object
getJavaFXTask
(BackgroundTask<V>
the BackgroundTask to wrap
task
)

Generates a wrapper JavaFX Task monitoring the progress based on the data given from the task.

public static void
runAndWaitInJavaFXThread(Runnable
the Runnable to run
action
)

Runs the specified Runnable on the JavaFX application thread and waits for completion.

public static <V> V
public static void
public <V> Future<?>
schedule(BackgroundTask<V>
the task to execute
task
,
long
the time from now to delay execution
delay
,
TimeUnit
the time unit of the delay parameter
unit
)

Implements org.jabref.gui.util.TaskExecutor.schedule.

Submits a one-shot task that becomes enabled after the given delay.

public void
shutdown()

Implements org.jabref.gui.util.TaskExecutor.shutdown.

Shuts everything down.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

executorback to summary
private final ExecutorService executor
LOGGERback to summary
private static final Logger LOGGER
scheduledExecutorback to summary
private final ScheduledExecutorService scheduledExecutor
throttlersback to summary
private final WeakHashMap<DelayTaskThrottler, Void> throttlers

Constructor Detail

UiTaskExecutorback to summary
public UiTaskExecutor()

Method Detail

convertToExceptionback to summary
private Exception convertToException(Throwable throwable)
createThrottlerback to summary
public DelayTaskThrottler createThrottler(int delay)

Implements org.jabref.gui.util.TaskExecutor.createThrottler.

Doc from org.jabref.gui.util.TaskExecutor.createThrottler.

Creates a new task throttler, and registers it so that it gets properly shutdown.

Annotations
@Override
executeback to summary
public <V> Future<V> execute(BackgroundTask<V> task)

Implements org.jabref.gui.util.TaskExecutor.execute.

Doc from org.jabref.gui.util.TaskExecutor.execute.

Runs the given task and returns a Future representing that task.

Parameters
<V>
type of return value of the task
task:BackgroundTask<V>

the task to run

Annotations
@Override
executeback to summary
public <V> Future<V> execute(Task<V> task)

Implements org.jabref.gui.util.TaskExecutor.execute.

Doc from org.jabref.gui.util.TaskExecutor.execute.

Runs the given task and returns a Future representing that task. Usually, you want to use the other method execute(BackgroundTask).

Parameters
<V>
type of return value of the task
task:Task<V>

the task to run

Annotations
@Override
getJavaFXTaskback to summary
private <V> Task<V> getJavaFXTask(BackgroundTask<V> task)

Generates a wrapper JavaFX Task monitoring the progress based on the data given from the task. call is routed to the given task object.

Parameters
task:BackgroundTask<V>

the BackgroundTask to wrap

Returns:Task<V>

a new Task object

runAndWaitInJavaFXThreadback to summary
public static void runAndWaitInJavaFXThread(Runnable action)

Runs the specified Runnable on the JavaFX application thread and waits for completion.

Parameters
action:Runnable

the Runnable to run

Exceptions
NullPointerException:
if action is null
runInJavaFXThreadback to summary
public static <V> V runInJavaFXThread(Callable<V> callable)
runInJavaFXThreadback to summary
public static void runInJavaFXThread(Runnable runnable)
scheduleback to summary
public <V> Future<?> schedule(BackgroundTask<V> task, long delay, TimeUnit unit)

Implements org.jabref.gui.util.TaskExecutor.schedule.

Doc from org.jabref.gui.util.TaskExecutor.schedule.

Submits a one-shot task that becomes enabled after the given delay.

Parameters
task:BackgroundTask<V>

the task to execute

delay:long

the time from now to delay execution

unit:TimeUnit

the time unit of the delay parameter

Returns:Future<?>

a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion

Annotations
@Override
shutdownback to summary
public void shutdown()

Implements org.jabref.gui.util.TaskExecutor.shutdown.

Shuts everything down. After termination, this method returns.

Annotations
@Override