Task.
We cannot use 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 org.: Use TaskExecutor#execute(BackgroundTask) to submit.
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 |
|---|---|
| protected static record |
| Modifier and Type | Field and Description |
|---|---|
| public static ImmutableMap | |
| 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 |
|---|---|
| protected abstract V | |
| public void | |
| private static <T> Consumer | |
| public Future | |
| public static Node | |
| pack-priv Consumer | |
| pack-priv Runnable | |
| pack-priv Consumer | |
| protected BackgroundTask. | |
| public double | |
| public boolean | |
| public BooleanProperty | |
| public StringProperty | |
| public BackgroundTask | |
| public BackgroundTask | onFinished(Runnable onFinished)
Sets the |
| public BackgroundTask | |
| public BackgroundTask | |
| protected ObjectProperty | |
| public Future | |
| public boolean | |
| public BackgroundTask | |
| 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 | |
| protected void | |
| public boolean | |
| public void | |
| public BackgroundTask | |
| public DoubleProperty | |
| public static <V> BackgroundTask | |
| public static BackgroundTask |
| iconMap | back to summary |
|---|---|
| public static ImmutableMap<String, Node> iconMap | |
| isCanceled | back to summary |
|---|---|
| private final BooleanProperty isCanceled | |
| 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 |
|---|---|
| protected 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 | |
| getIcon | back to summary |
|---|---|
| public static Node getIcon(Task<?> task) | |
| getOnException | back to summary |
|---|---|
| pack-priv Consumer | |
| getOnRunning | back to summary |
|---|---|
| pack-priv Runnable getOnRunning() | |
| getOnSuccess | back to summary |
|---|---|
| pack-priv Consumer | |
| getProgress | back to summary |
|---|---|
| protected BackgroundTask. | |
| getWorkDonePercentage | back to summary |
|---|---|
| public double getWorkDonePercentage() | |
| isCanceled | back to summary |
|---|---|
| public boolean isCanceled() | |
| isCanceledProperty | back to summary |
|---|---|
| public BooleanProperty isCanceledProperty() | |
| 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 |
|---|---|
| protected ObjectProperty | |
| scheduleWith | back to summary |
|---|---|
| public Future | |
| showToUser | back to summary |
|---|---|
| public boolean showToUser() | |
| showToUser | back to summary |
|---|---|
| public BackgroundTask | |
| 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 |
|---|---|
| protected void updateProgress(double workDone, double max) | |
| willBeRecoveredAutomatically | back to summary |
|---|---|
| public boolean willBeRecoveredAutomatically() | |
| willBeRecoveredAutomatically | back to summary |
|---|---|
| public void willBeRecoveredAutomatically(boolean willBeRecoveredAutomatically) | |
| 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 |
|---|---|
| protected |
| 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 |
|---|---|
| protected 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. | |