Class MCRProcessableSupplier<R>
java.lang.Object
org.mycore.common.processing.MCRAbstractProgressable
org.mycore.common.processing.MCRAbstractProcessable
org.mycore.common.processing.MCRProcessableTask<Callable<R>>
org.mycore.util.concurrent.processing.MCRProcessableSupplier<R>
- Type Parameters:
R
- the result of the task
- All Implemented Interfaces:
Supplier<R>
,MCRListenableProgressable
,MCRProcessable
,MCRProgressable
public class MCRProcessableSupplier<R>
extends MCRProcessableTask<Callable<R>>
implements Supplier<R>
A processable supplier combines a
Supplier
and a MCRProcessable
.
The supplier will be executed with the help of an CompletableFuture
.
To get the future call getFuture()
.- Author:
- Matthias Eichner
-
Field Summary
Fields inherited from class org.mycore.common.processing.MCRProcessableTask
task
Fields inherited from class org.mycore.common.processing.MCRAbstractProcessable
createTime, endTime, error, name, properties, startTime, status, statusListener, userId
Fields inherited from class org.mycore.common.processing.MCRAbstractProgressable
progress, progressListener, progressText
-
Method Summary
Modifier and TypeMethodDescriptionboolean
cancel
(boolean mayInterruptIfRunning) Same asFuture.cancel(boolean)
.get()
Gets the result of the task.The future the task is assigned to.getName()
Returns the name of this process.Returns an integer between 0-100 indicating the progress of the processable.Returns a human readable text indicating the state of the progress.boolean
Returns true if this task completed.static <T> MCRProcessableSupplier<T>
of
(Callable<T> task, CompletableFuture<T> future) Creates a newMCRProcessableSupplier
by the already committed task and its future.static <T> MCRProcessableSupplier<T>
of
(Callable<T> task, ExecutorService executorService, Integer priority) Creates a newMCRProcessableSupplier
by submitting the task to the executorService with the given priority.Methods inherited from class org.mycore.common.processing.MCRProcessableTask
delegateProgressable, getTask
Methods inherited from class org.mycore.common.processing.MCRAbstractProcessable
addStatusListener, fireStatusChanged, getCreateTime, getEndTime, getError, getProperties, getStartTime, getStatus, getUserId, removeStatusListener, setError, setName, setStatus, setUserId
Methods inherited from class org.mycore.common.processing.MCRAbstractProgressable
addProgressListener, fireProgressChanged, fireProgressTextChanged, removeProgressListener, setProgress, setProgressText
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.mycore.common.processing.MCRListenableProgressable
addProgressListener, removeProgressListener
Methods inherited from interface org.mycore.common.processing.MCRProcessable
getProperty, getPropertyAs, isCanceled, isCreated, isDone, isFailed, isProcessing, isSuccessful, took
-
Field Details
-
future
-
-
Method Details
-
of
Creates a newMCRProcessableSupplier
by the already committed task and its future.- Parameters:
task
- the task which should be executedfuture
- the future- Returns:
- a new processable supplier
-
of
public static <T> MCRProcessableSupplier<T> of(Callable<T> task, ExecutorService executorService, Integer priority) Creates a newMCRProcessableSupplier
by submitting the task to the executorService with the given priority.- Parameters:
task
- the task to submitexecutorService
- the executor servicepriority
- the priority- Returns:
- a new processable supplier
-
get
Gets the result of the task. Will usually be called by the executor service and should not be executed directly. -
getFuture
The future the task is assigned to.- Returns:
- the future
-
isFutureDone
public boolean isFutureDone()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.- Returns:
- true if this task completed
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Same asFuture.cancel(boolean)
.- Parameters:
mayInterruptIfRunning
- true if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete- Returns:
- false if the task could not be cancelled, typically because it has already completed normally; true otherwise
-
getProgress
Returns an integer between 0-100 indicating the progress of the processable. Can return null if the task is not started yet or the task is not an instance ofMCRProgressable
.- Specified by:
getProgress
in interfaceMCRProgressable
- Overrides:
getProgress
in classMCRAbstractProgressable
- Returns:
- the progress between 0-100 or null
-
getProgressText
Returns a human readable text indicating the state of the progress.- Specified by:
getProgressText
in interfaceMCRProgressable
- Overrides:
getProgressText
in classMCRAbstractProgressable
- Returns:
- progress text
-
getName
Returns the name of this process. If no name is set this returns the simplified class name of the task.- Specified by:
getName
in interfaceMCRProcessable
- Overrides:
getName
in classMCRAbstractProcessable
- Returns:
- a human readable name of this processable task
-