javafx.concurrent.Task
.
We cannot use javafx.concurrent.Task
directly since it runs certain update notifications on the JavaFX thread,
and so makes testing harder.
We take the opportunity and implement a fluid interface.
A task created here is to be submitted to TaskExecutor#execute(BackgroundTask)
to submit.
This class is injected at @Inject TaskExecutor
Example (for using the fluent interface)
BackgroundTask
.wrap(() -> ...)
.showToUser(true)
.onRunning(() -> ...)
.onSuccess(() -> ...)
.onFailure(() -> ...)
.executeWith(taskExecutor);
Background: The task executor one takes care to show it in the UI. See org.jabref.gui.StateManager#addBackgroundTask(BackgroundTask, Task)
for details.Todo
Think of migrating to RxJava; CompletableFuture do not seem to support everything. If this is not possible, add an @implNote why.
Modifier and Type | Class and Description |
---|---|
public static record |
Modifier and Type | Field and Description |
---|---|
private final BooleanProperty | |
private static final Logger | |
private final StringProperty | |
private Consumer | |
private Runnable | |
private Runnable | |
private Consumer | |
private final ObjectProperty | |
private final BooleanProperty | |
private final StringProperty | |
private final BooleanProperty | |
private final DoubleProperty |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public abstract V | |
public void | |
private static <T> Consumer | |
public Future | |
public Consumer | |
public Runnable | |
public Consumer | |
protected BackgroundTask. | |
public double | |
public boolean | |
public BooleanProperty | |
public StringProperty | |
public BackgroundTask | |
public BackgroundTask | onFinished(Runnable onFinished)
Sets the |
public BackgroundTask | |
public BackgroundTask | |
public ObjectProperty | |
public Future | |
public BackgroundTask | |
public boolean | |
public BackgroundTask | |
public BooleanProperty | |
public < type of the return value of the second task T> BackgroundTask | then(Function<V, BackgroundTask<T>>
the function that creates the new task nextTaskFactory)Creates a |
public < type of the return value of the second task T> BackgroundTask | thenRun(Function<V, T>
the function that performs the next operation nextOperation)Creates a |
public BackgroundTask | thenRun(Consumer<V>
the function that performs the next operation nextOperation)Creates a |
public StringProperty | |
public void | |
protected void | |
public void | |
public boolean | |
public BackgroundTask | |
public BackgroundTask | |
public DoubleProperty | |
public static <V> BackgroundTask | |
public static BackgroundTask |
isCancelled | back to summary |
---|---|
private final BooleanProperty isCancelled |
LOGGER | back to summary |
---|---|
private static final Logger LOGGER |
message | back to summary |
---|---|
private final StringProperty message |
onException | back to summary |
---|---|
private Consumer<Exception> onException |
onFinished | back to summary |
---|---|
private Runnable onFinished |
onRunning | back to summary |
---|---|
private Runnable onRunning |
onSuccess | back to summary |
---|---|
private Consumer<V> onSuccess |
progress | back to summary |
---|---|
private final ObjectProperty<BackgroundTask. |
showToUser | back to summary |
---|---|
private final BooleanProperty showToUser |
title | back to summary |
---|---|
private final StringProperty title |
willBeRecoveredAutomatically | back to summary |
---|---|
private final BooleanProperty willBeRecoveredAutomatically |
workDonePercentage | back to summary |
---|---|
private final DoubleProperty workDonePercentage |
BackgroundTask | back to summary |
---|---|
public BackgroundTask() |
call | back to summary |
---|---|
public abstract V call() throws Exception |
cancel | back to summary |
---|---|
public void cancel() |
chain | back to summary |
---|---|
private static <T> Consumer |
executeWith | back to summary |
---|---|
public Future |
getOnException | back to summary |
---|---|
public Consumer |
getOnRunning | back to summary |
---|---|
public Runnable getOnRunning() |
getOnSuccess | back to summary |
---|---|
public Consumer |
getProgress | back to summary |
---|---|
protected BackgroundTask. |
getWorkDonePercentage | back to summary |
---|---|
public double getWorkDonePercentage() |
isCancelled | back to summary |
---|---|
public boolean isCancelled() |
isCancelledProperty | back to summary |
---|---|
public BooleanProperty isCancelledProperty() |
messageProperty | back to summary |
---|---|
public StringProperty messageProperty() |
onFailure | back to summary |
---|---|
public BackgroundTask Sets the |
onFinished | back to summary |
---|---|
public BackgroundTask Sets the |
onRunning | back to summary |
---|---|
public BackgroundTask Sets the |
onSuccess | back to summary |
---|---|
public BackgroundTask Sets the |
progressProperty | back to summary |
---|---|
public ObjectProperty |
scheduleWith | back to summary |
---|---|
public Future |
setTitle | back to summary |
---|---|
public BackgroundTask |
showToUser | back to summary |
---|---|
public boolean showToUser() |
showToUser | back to summary |
---|---|
public BackgroundTask |
showToUserProperty | back to summary |
---|---|
public BooleanProperty showToUserProperty() |
then | back to summary |
---|---|
public <T> BackgroundTask Creates a
|
thenRun | back to summary |
---|---|
public <T> BackgroundTask Creates a
|
thenRun | back to summary |
---|---|
public BackgroundTask Creates a
|
titleProperty | back to summary |
---|---|
public StringProperty titleProperty() |
updateMessage | back to summary |
---|---|
public void updateMessage(String newMessage) |
updateProgress | back to summary |
---|---|
protected void updateProgress(BackgroundTask. |
updateProgress | back to summary |
---|---|
public void updateProgress(double workDone, double max) |
willBeRecoveredAutomatically | back to summary |
---|---|
public boolean willBeRecoveredAutomatically() |
willBeRecoveredAutomatically | back to summary |
---|---|
public BackgroundTask |
withInitialMessage | back to summary |
---|---|
public BackgroundTask |
workDonePercentageProperty | back to summary |
---|---|
public DoubleProperty workDonePercentageProperty() |
wrap | back to summary |
---|---|
public static <V> BackgroundTask |
wrap | back to summary |
---|---|
public static BackgroundTask |
Modifier and Type | Field and Description |
---|---|
private final double | |
private final double | workDone
Record Component accessed by workDone(). |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public final boolean | equals(Object
the reference object with which to compare. o)Implements abstract java. Indicates whether some other object is "equal to" this one. |
public double | |
public final int | |
public double | |
public final String | toString()
Implements abstract java. Returns a string representation of the record. |
public double |
max | back to summary |
---|---|
private final double max Record Component accessed by max(). |
workDone | back to summary |
---|---|
private final double workDone Record Component accessed by workDone(). |
BackgroundProgress | back to summary |
---|---|
public BackgroundProgress(double workDone, double max) |
equals | back to summary |
---|---|
public final boolean equals(Object o) Implements abstract java. Doc from java. Indicates whether some other object is "equal to" this one. In addition
to the general contract of R copy = new R(r.c1(), r.c2(), ..., r.cn());then it must be the case that r.equals(copy) .
|
getWorkDonePercentage | back to summary |
---|---|
public double getWorkDonePercentage() |
hashCode | back to summary |
---|---|
public final int hashCode() Implements abstract java. Doc from java. Returns a hash code value for the record.
Obeys the general contract of
|
max | back to summary |
---|---|
public double max() Record Component getter of max. |
toString | back to summary |
---|---|
public final String toString() Implements abstract java. Doc from java. Returns a string representation of the record.
In accordance with the general contract of In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.
|
workDone | back to summary |
---|---|
public double workDone() Record Component getter of workDone. |