Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.logic.util

public Class CurrentThreadTaskExecutor

extends Object
implements TaskExecutor
Class Inheritance
All Implemented Interfaces
org.jabref.logic.util.TaskExecutor
Imports
java.util.WeakHashMap, java.util.concurrent.CompletableFuture, .ExecutionException, .Future, .TimeUnit, java.util.function.Consumer, org.slf4j.Logger, .LoggerFactory

Implementation of TaskExecutor that runs every task on the current thread, i.e. in a sequential order. This class is not designed to be used in production but should make code involving asynchronous operations deterministic and testable.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

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

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

Implements org.jabref.logic.util.TaskExecutor.createThrottler.

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

public <V> Future<V>
execute(BackgroundTask<V> task)

Implements org.jabref.logic.util.TaskExecutor.execute.

Executes the task on the current thread.

public <V> Future<?>
schedule(BackgroundTask<V> task, long delay, TimeUnit unit)

Implements org.jabref.logic.util.TaskExecutor.schedule.

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

public void
shutdown()

Implements org.jabref.logic.util.TaskExecutor.shutdown.

Shutdown the task executor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER
throttlersback to summary
private final WeakHashMap<DelayTaskThrottler, Void> throttlers

Constructor Detail

CurrentThreadTaskExecutorback to summary
public CurrentThreadTaskExecutor()

Method Detail

createThrottlerback to summary
public DelayTaskThrottler createThrottler(int delay)

Implements org.jabref.logic.util.TaskExecutor.createThrottler.

Doc from org.jabref.logic.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.logic.util.TaskExecutor.execute.

Executes the task on the current thread. The code is essentially taken from javafx.concurrent.Task.TaskCallable#call(), but adapted to run sequentially.

Annotations
@Override
scheduleback to summary
public <V> Future<?> schedule(BackgroundTask<V> task, long delay, TimeUnit unit)

Implements org.jabref.logic.util.TaskExecutor.schedule.

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

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

Annotations
@Override
shutdownback to summary
public void shutdown()

Implements org.jabref.logic.util.TaskExecutor.shutdown.

Doc from org.jabref.logic.util.TaskExecutor.shutdown.

Shutdown the task executor. May happen in the background or may be finished when this method returns.

Annotations
@Override
org.jabref.logic.util back to summary

private final Record CurrentThreadTaskExecutor.FailedFuture<T>

extends Record
implements Future<T>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Future
Record Components
exception:Throwable 

Field Summary

Modifier and TypeField and Description
private final Throwable
exception

Record Component accessed by exception().

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public Throwable
exception()

Record Component getter of exception.

public T
get()

Implements java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

public T
get(long timeout, TimeUnit unit)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public boolean
isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

exceptionback to summary
private final Throwable exception

Record Component accessed by exception().

Constructor Detail

FailedFutureback to summary
private FailedFuture(Throwable exception)

Method Detail

cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task. This method has no effect if the task is already completed or cancelled, or could not be cancelled for some other reason. Otherwise, if this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

Annotations
@Override
equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
exceptionback to summary
public Throwable exception()

Record Component getter of exception.

getback to summary
public T get() throws ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

Annotations
@Override
Exceptions
ExecutionException:
if the computation threw an exception
getback to summary
public T get(long timeout, TimeUnit unit) throws ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Annotations
@Override
Exceptions
ExecutionException:
if the computation threw an exception
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Doc from java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Annotations
@Override
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

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.