Class DAGraph<DataT,NodeT extends DAGNode<DataT,NodeT>>
- java.lang.Object
-
- com.azure.resourcemanager.resources.fluentcore.dag.Graph<DataT,NodeT>
-
- com.azure.resourcemanager.resources.fluentcore.dag.DAGraph<DataT,NodeT>
-
- Type Parameters:
DataT- the type of the data stored in the graph nodesNodeT- the type of the nodes in the graph
- Direct Known Subclasses:
TaskGroup
public class DAGraph<DataT,NodeT extends DAGNode<DataT,NodeT>> extends Graph<DataT,NodeT>
Type representing a DAG (directed acyclic graph).each node in a DAG is represented by
DAGNode
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.azure.resourcemanager.resources.fluentcore.dag.Graph
Graph.EdgeType, Graph.Visitor<U>
-
-
Field Summary
Fields Modifier and Type Field Description protected List<DAGraph<DataT,NodeT>>parentDAGsthe immediate parent graphs of this graph.protected ConcurrentLinkedQueue<String>queueto perform topological sort on the graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDependencyGraph(DAGraph<DataT,NodeT> dependencyGraph)Mark root of this DAG depends on given DAG's root.voidaddDependentGraph(DAGraph<DataT,NodeT> dependentGraph)Mark root of the given DAG depends on this DAG's root.NodeTgetNext()Gets next node in the DAG which has no dependency or all of it's dependencies are resolved and ready to be consumed.NodeTgetNode(String key)Gets a node from the graph with the given key.booleanhasParents()booleanisPreparer()booleanisRootNode(NodeT node)Checks whether the given node is root node of this DAG.voidprepareForEnumeration()Prepares this DAG for node enumeration using getNext method, each call to getNext returns next node in the DAG with no dependencies.voidreportCompletion(NodeT completed)Reports that a node is resolved hence other nodes depends on it can consume it.voidreportError(NodeT faulted, Throwable throwable)Reports that a node is faulted.protected NodeTroot()
-
-
-
Field Detail
-
parentDAGs
protected List<DAGraph<DataT,NodeT extends DAGNode<DataT,NodeT>>> parentDAGs
the immediate parent graphs of this graph. A parent graph is the one with it's root depends on this graph's root.
-
queue
protected ConcurrentLinkedQueue<String> queue
to perform topological sort on the graph. During sorting queue contains the nodes which are ready to invoke.
-
-
Constructor Detail
-
DAGraph
public DAGraph(NodeT rootNode)
Creates a new DAG.- Parameters:
rootNode- the root node of this DAG
-
-
Method Detail
-
hasParents
public boolean hasParents()
- Returns:
- true if this DAG is merged with one or more DAG and hence has parents
-
root
protected NodeT root()
- Returns:
- the root node of the DAG.
-
isRootNode
public boolean isRootNode(NodeT node)
Checks whether the given node is root node of this DAG.- Parameters:
node- the nodeDAGNodeto be checked- Returns:
- true if the given node is root node
-
isPreparer
public boolean isPreparer()
- Returns:
- true if this dag is the preparer responsible for preparing the DAG for traversal.
-
getNode
public NodeT getNode(String key)
Gets a node from the graph with the given key.- Parameters:
key- the key of the node- Returns:
- the node
-
addDependencyGraph
public void addDependencyGraph(DAGraph<DataT,NodeT> dependencyGraph)
Mark root of this DAG depends on given DAG's root.- Parameters:
dependencyGraph- the dependency DAG
-
addDependentGraph
public void addDependentGraph(DAGraph<DataT,NodeT> dependentGraph)
Mark root of the given DAG depends on this DAG's root.- Parameters:
dependentGraph- the dependent DAG
-
prepareForEnumeration
public void prepareForEnumeration()
Prepares this DAG for node enumeration using getNext method, each call to getNext returns next node in the DAG with no dependencies.
-
getNext
public NodeT getNext()
Gets next node in the DAG which has no dependency or all of it's dependencies are resolved and ready to be consumed.- Returns:
- next node or null if all the nodes have been explored or no node is available at this moment.
-
reportCompletion
public void reportCompletion(NodeT completed)
Reports that a node is resolved hence other nodes depends on it can consume it.- Parameters:
completed- the node ready to be consumed
-
-