DAGraph<DataT,NodeT,NodeT> Class

  • java.lang.Object

Type Parameters

DataT

the type of the data stored in the graph nodes

NodeT

the type of the nodes in the graph

NodeT

the type of the nodes in the graph

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<DataT,NodeT>

Constructor Summary

Constructor Description
DAGraph(NodeT rootNode)

Creates a new DAG.

Method Summary

Modifier and Type Method and Description
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 hasParent()
boolean isPreparer()
boolean isRootNode(NodeT node)

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

void merge(DAGraph<DataT, NodeT> parent)

Merge this DAG with another DAG.

This will mark this DAG as a child DAG, the dependencies of nodes in this DAG will be merged with (copied to) the parent DAG

void mergeChildToParent(String parentKey, NodeT childNode)

Merges DAG associated with childNode to DAG associated with a parent node of given key.

void prepare()

Prepares this DAG for traversal 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.

Inherited Members

Constructor Details

DAGraph

public DAGraph(NodeT rootNode)

Creates a new DAG.

Parameters:

rootNode - the root node of this DAG

Method Details

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

hasParent

public boolean hasParent()

Returns:

true if this DAG is merged with another DAG and hence has a parent

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

merge

public void merge(DAGraph parent)

Merge this DAG with another DAG.

This will mark this DAG as a child DAG, the dependencies of nodes in this DAG will be merged with (copied to) the parent DAG

Parameters:

parent - the parent DAG

mergeChildToParent

public void mergeChildToParent(String parentKey, NodeT childNode)

Merges DAG associated with childNode to DAG associated with a parent node of given key.

Parameters:

parentKey - the key of the parent node
childNode - the child node

prepare

public void prepare()

Prepares this DAG for traversal 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

Applies to