Class TaskGraph

java.lang.Object
org.jppf.node.protocol.graph.TaskGraph
All Implemented Interfaces:
Serializable

public class TaskGraph extends Object implements Serializable
A graph of the tasks in a job, representing the "depends on" relationships between tasks. Each task is represented by its position in the job as an Integer value.

Dependency cycles are not allowed, making this graph effectively a Directed Acyclic Graph (DAG). This allows, among other things to compute one or more topological orders for the tasks.

Author:
Laurent Cohen
See Also:
  • Constructor Details

    • TaskGraph

      public TaskGraph()
      No-arg constrcutor used for custom (de)serialization.
    • TaskGraph

      public TaskGraph(Collection<TaskGraph.Node> nodes)
      Create this graph from the specified collection of nodes.
      Parameters:
      nodes - the nodes that constitute the graph.
    • TaskGraph

      public TaskGraph(Map<Integer,TaskGraph.Node> nodes)
      Create this graph form the specified collection of nodes.
      Parameters:
      nodes - the nodes that constitute the graph.
  • Method Details

    • nodeAt

      public TaskGraph.Node nodeAt(int position)
      Perform a depth-first search topological sort.
      Parameters:
      position - the position of the node to lookup.
      Returns:
      the TaskGraph.Node at the specified position, or {@link null} if there isn't one.
    • nodeDone

      public void nodeDone(int position)
      Called when a task has completed or was cancelled.
      Parameters:
      position - the position of hte task in the job.
    • getAvailableNodes

      public Set<Integer> getAvailableNodes()
      Returns:
      the set of non-executed tasks that no longer have pending dependencies.
    • isDone

      public boolean isDone()
      Returns:
      whether all task in the job graph are odne.
    • isDependendOn

      public boolean isDependendOn(int position)
      Determine whether a task at the given position has tasks that depend on it.
      Parameters:
      position - the position of the task in the job.
      Returns:
      true if the task has other tasks that depend on it, false otherwise.
    • topologicalSortDFS

      public List<Integer> topologicalSortDFS()
      Returns:
      a list of node positions in topological order.
      See Also:
    • startVisit

      public void startVisit(TaskNodeVisitor visitor)
      Start the visit of all the nodes in the graph.
      Parameters:
      visitor - the visitor function to use.
    • startVisitNotDone

      public void startVisitNotDone(TaskNodeVisitor visitor)
      Start the visit of the graph nodes that are not done.
      Parameters:
      visitor - the visitor function to use.
    • serialize

      public void serialize(OutputStream out) throws IOException
      Save the state of this object to a stream (i.e.,serialize it).
      Parameters:
      out - the output stream to which to write this object.
      Throws:
      IOException - if any I/O error occurs.
    • deserialize

      public void deserialize(InputStream in) throws IOException, ClassNotFoundException
      Reconstitute this object from a stream (i.e., deserialize it).
      Parameters:
      in - the input stream from which to read the object.
      Throws:
      IOException - if any I/O error occurs.
      ClassNotFoundException - if the class of an object in the object graph could not be found.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getDoneCount

      public int getDoneCount()
      Returns:
      the count of completed tasks.