Package org.jppf.node.protocol.graph
Class TaskGraph
java.lang.Object
org.jppf.node.protocol.graph.TaskGraph
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA node in the graph of the tasks in a job which represents a task and its dependants. -
Constructor Summary
ConstructorsConstructorDescriptionNo-arg constrcutor used for custom (de)serialization.TaskGraph(Collection<TaskGraph.Node> nodes) Create this graph from the specified collection of nodes.TaskGraph(Map<Integer, TaskGraph.Node> nodes) Create this graph form the specified collection of nodes. -
Method Summary
Modifier and TypeMethodDescriptionvoidReconstitute this object from a stream (i.e., deserialize it).intbooleanisDependendOn(int position) Determine whether a task at the given position has tasks that depend on it.booleanisDone()nodeAt(int position) Perform a depth-first search topological sort.voidnodeDone(int position) Called when a task has completed or was cancelled.voidserialize(OutputStream out) Save the state of this object to a stream (i.e.,serialize it).voidstartVisit(TaskNodeVisitor visitor) Start the visit of all the nodes in the graph.voidstartVisitNotDone(TaskNodeVisitor visitor) Start the visit of the graph nodes that are not done.toString()
-
Constructor Details
-
TaskGraph
public TaskGraph()No-arg constrcutor used for custom (de)serialization. -
TaskGraph
Create this graph from the specified collection of nodes.- Parameters:
nodes- the nodes that constitute the graph.
-
TaskGraph
Create this graph form the specified collection of nodes.- Parameters:
nodes- the nodes that constitute the graph.
-
-
Method Details
-
nodeAt
Perform a depth-first search topological sort.- Parameters:
position- the position of the node to lookup.- Returns:
- the
TaskGraph.Nodeat 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
- 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:
trueif the task has other tasks that depend on it,falseotherwise.
-
topologicalSortDFS
- Returns:
- a list of node positions in topological order.
- See Also:
-
- topological sorting on Wikipedia.
-
startVisit
Start the visit of all the nodes in the graph.- Parameters:
visitor- the visitor function to use.
-
startVisitNotDone
Start the visit of the graph nodes that are not done.- Parameters:
visitor- the visitor function to use.
-
serialize
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
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
-
getDoneCount
public int getDoneCount()- Returns:
- the count of completed tasks.
-