Package org.jtrim2.taskgraph.basic
Class RestrictableTaskGraphExecutor
java.lang.Object
org.jtrim2.taskgraph.basic.RestrictableTaskGraphExecutor
- All Implemented Interfaces:
TaskGraphExecutor
Defines an implementation of
TaskGraphExecutor
allowing to restrict task node
execution using an externally provided custom strategy
.
Thread safety
The methods of this class are not expected to be callable from multiple threads concurrently.Synchronization transparency
The methods of this class are not synchronization transparent.- See Also:
-
Constructor Summary
ConstructorDescriptionRestrictableTaskGraphExecutor
(DependencyDag<TaskNodeKey<?, ?>> graph, Iterable<? extends TaskNode<?, ?>> nodes, TaskExecutionRestrictionStrategyFactory restrictionStrategyFactory) Creates a newRestrictableTaskGraphExecutor
with the given task graph, nodes and task execution restriction strategy. -
Method Summary
Modifier and TypeMethodDescriptionexecute
(CancellationToken cancelToken) Starts executing the associated task graph and will notify the returnedCompletionStage
once task execution terminates.<R> CompletionStage<R>
futureOf
(TaskNodeKey<R, ?> nodeKey) Returns theCompletionStage
tracking the completion of the given task node.Returns the whole task graph to be executed.Returns the properties used for executing the task graph.
-
Constructor Details
-
RestrictableTaskGraphExecutor
public RestrictableTaskGraphExecutor(DependencyDag<TaskNodeKey<?, ?>> graph, Iterable<? extends TaskNode<?, ?>> nodes, TaskExecutionRestrictionStrategyFactory restrictionStrategyFactory) Creates a newRestrictableTaskGraphExecutor
with the given task graph, nodes and task execution restriction strategy.- Parameters:
graph
- the task execution graph defining the dependencies between task nodes. This argument cannot benull
.nodes
- the task nodes to be executed. The execution must honor the dependencies defined by the task graph. This argument cannot benull
and may not containnull
elements.restrictionStrategyFactory
- the strategy which may restrict some nodes from being executed to prevent too much concurrent resource consumption. This argument cannot benull
.
-
-
Method Details
-
properties
Returns the properties used for executing the task graph. The properties must be set before calling theexecute
method.- Specified by:
properties
in interfaceTaskGraphExecutor
- Returns:
- the properties used for executing the task graph. This method never returns
null
.
-
getBuiltGraph
Returns the whole task graph to be executed. This method may only be called before executing the task graph.- Specified by:
getBuiltGraph
in interfaceTaskGraphExecutor
- Returns:
- the whole task graph to be executed. This method never returns
null
.
-
futureOf
Returns theCompletionStage
tracking the completion of the given task node.Note that the returned
CompletionStage
might be notified after the task graph execution terminates. Therefore, it is usually recommended to combine the returnedCompletionStage
with future of the task graph execution.- Specified by:
futureOf
in interfaceTaskGraphExecutor
- Type Parameters:
R
- the type of the result of the requested node- Parameters:
nodeKey
- the node key identifying the task node whoseCompletionStage
is requested. The node with this id must exist. This argument cannot benull
.- Returns:
- the
CompletionStage
tracking the completion of the given task node. This method never returnsnull
. - See Also:
-
execute
Starts executing the associated task graph and will notify the returnedCompletionStage
once task execution terminates.If the
deliverResultOnFailure
property istrue
, theCompletionStage
will never be completed exceptionally. However, if it isfalse
, the possible exceptional results are:TaskGraphExecutionException
: At least one node failed with an exception.-
OperationCanceledException
: The execution was canceled before it could have been completed and no nodes failed with an unexpected exception (i.e., notOperationCanceledException
). Note that nodes might fail with aTaskSkippedException
which is not considered as a failure, nor a cancellation. - Any other exception: When some unexpected issues prevented the task graph execution to complete.
- Specified by:
execute
in interfaceTaskGraphExecutor
- Parameters:
cancelToken
- theCancellationToken
which can be used to cancel the execution of the task graph. The framework will make a best effort to cancel the execution. However, there is no guarantee that cancellation request will be fulfilled. If cancellation succeeds, theCompletionStage
will complete exceptionally with anOperationCanceledException
.- Returns:
- the
CompletionStage
which is notified whenever the task graph execution terminates (normally or abnormally). This method never returnsnull
.
-