Class RestrictableTaskGraphExecutor

java.lang.Object
org.jtrim2.taskgraph.basic.RestrictableTaskGraphExecutor
All Implemented Interfaces:
TaskGraphExecutor

public final class RestrictableTaskGraphExecutor extends Object implements 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 Details

    • RestrictableTaskGraphExecutor

      public RestrictableTaskGraphExecutor(DependencyDag<TaskNodeKey<?,?>> graph, Iterable<? extends TaskNode<?,?>> nodes, TaskExecutionRestrictionStrategyFactory restrictionStrategyFactory)
      Creates a new RestrictableTaskGraphExecutor 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 be null.
      nodes - the task nodes to be executed. The execution must honor the dependencies defined by the task graph. This argument cannot be null and may not contain null elements.
      restrictionStrategyFactory - the strategy which may restrict some nodes from being executed to prevent too much concurrent resource consumption. This argument cannot be null.
  • Method Details

    • properties

      Returns the properties used for executing the task graph. The properties must be set before calling the execute method.
      Specified by:
      properties in interface TaskGraphExecutor
      Returns:
      the properties used for executing the task graph. This method never returns null.
    • getBuiltGraph

      public BuiltGraph getBuiltGraph()
      Returns the whole task graph to be executed. This method may only be called before executing the task graph.
      Specified by:
      getBuiltGraph in interface TaskGraphExecutor
      Returns:
      the whole task graph to be executed. This method never returns null.
    • futureOf

      public <R> CompletionStage<R> futureOf(TaskNodeKey<R,?> nodeKey)
      Returns the CompletionStage 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 returned CompletionStage with future of the task graph execution.

      Specified by:
      futureOf in interface TaskGraphExecutor
      Type Parameters:
      R - the type of the result of the requested node
      Parameters:
      nodeKey - the node key identifying the task node whose CompletionStage is requested. The node with this id must exist. This argument cannot be null.
      Returns:
      the CompletionStage tracking the completion of the given task node. This method never returns null.
      See Also:
    • execute

      Starts executing the associated task graph and will notify the returned CompletionStage once task execution terminates.

      If the deliverResultOnFailure property is true, the CompletionStage will never be completed exceptionally. However, if it is false, 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., not OperationCanceledException). Note that nodes might fail with a TaskSkippedException 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 interface TaskGraphExecutor
      Parameters:
      cancelToken - the CancellationToken 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, the CompletionStage will complete exceptionally with an OperationCanceledException.
      Returns:
      the CompletionStage which is notified whenever the task graph execution terminates (normally or abnormally). This method never returns null.