DAGraph<DataT,NodeT> Class

Type Parameters

DataT

the type of the data stored in the graph nodes

NodeT

the type of the nodes in the graph

public class DAGraph<DataT,NodeT>
extends Graph<DataT,NodeT>

Type representing a DAG (directed acyclic graph).

each node in a DAG is represented by DAGNode<DataT,NodeT>

Field Summary

Modifier and Type Field and Description
protected List<DAGraph<DataT,NodeT>> parentDAGs

the immediate parent graphs of this graph.

protected ConcurrentLinkedQueue<String> queue

to perform topological sort on the graph.

Constructor Summary

Constructor Description
DAGraph(NodeT rootNode)

Creates a new DAG.

Method Summary

Modifier and Type Method and Description
void addDependencyGraph(DAGraph<DataT,NodeT> dependencyGraph)

Mark root of this DAG depends on given DAG's root.

void addDependentGraph(DAGraph<DataT,NodeT> dependentGraph)

Mark root of the given DAG depends on this DAG's root.

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.

NodeT getNode(String key)

Gets a node from the graph with the given key.

boolean hasParents()
boolean isPreparer()
boolean isRootNode(NodeT node)

Checks whether the given node is root node of this DAG.

void prepareForEnumeration()

Prepares this DAG for node enumeration using getNext method, each call to getNext returns next node in the DAG with no dependencies.

void reportCompletion(NodeT completed)

Reports that a node is resolved hence other nodes depends on it can consume it.

void reportError(NodeT faulted, Throwable throwable)

Reports that a node is faulted.

protected NodeT root()

Methods inherited from Graph

Methods inherited from java.lang.Object

Field Details

parentDAGs

protected List<>> 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 queue

to perform topological sort on the graph. During sorting queue contains the nodes which are ready to invoke.

Constructor Details

DAGraph

public DAGraph(NodeT rootNode)

Creates a new DAG.

Parameters:

rootNode - the root node of this DAG

Method Details

addDependencyGraph

public void addDependencyGraph(DAGraph dependencyGraph)

Mark root of this DAG depends on given DAG's root.

Parameters:

dependencyGraph - the dependency DAG

addDependentGraph

public void addDependentGraph(DAGraph dependentGraph)

Mark root of the given DAG depends on this DAG's root.

Parameters:

dependentGraph - the dependent DAG

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.

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

hasParents

public boolean hasParents()

Returns:

true if this DAG is merged with one or more DAG and hence has parents

isPreparer

public boolean isPreparer()

Returns:

true if this dag is the preparer responsible for preparing the DAG for traversal.

isRootNode

public boolean isRootNode(NodeT node)

Checks whether the given node is root node of this DAG.

Parameters:

node - the node DAGNode<DataT,NodeT> to be checked

Returns:

true if the given node is root node

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.

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

reportError

public void reportError(NodeT faulted, Throwable throwable)

Reports that a node is faulted.

Parameters:

faulted - the node faulted
throwable - the reason for fault

root

protected NodeT root()

Returns:

the root node of the DAG.

Applies to