Class DAGraph<DataT,​NodeT extends DAGNode<DataT,​NodeT>>

  • Type Parameters:
    DataT - the type of the data stored in the graph nodes
    NodeT - 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

    • 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 node DAGNode to 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
      • reportError

        public void reportError​(NodeT faulted,
                                Throwable throwable)
        Reports that a node is faulted.
        Parameters:
        faulted - the node faulted
        throwable - the reason for fault