View Javadoc
1   package com.github.dexecutor.executor;
2   
3   import java.io.Writer;
4   
5   /**
6    * Main Interface for Dexecutor framework, It provides api to build the graph and and to kick off the execution.
7    * 
8    * @author Nadeem Mohammad
9    *
10   * @param <T>
11   */
12  public interface DependentTasksExecutor<T extends Comparable<T>> {
13  	/**
14  	 * Add a node as independent, it does not require any dependent node
15  	 * 
16  	 * @param nodeValue
17  	 */
18  	void addIndependent(final T nodeValue);
19  	/**
20  	 * <p>Add Two dependent nodes into the graph, creating the nodes if not already present </p>
21  	 * <p><code>evalFirstValue </code> would be executed first and then <code> evalAfterValue </code> </p>
22  	 * 
23  	 * @param evalFirstValue
24  	 * @param evalAfterValue
25  	 */
26  	void addDependency(final T evalFirstValue, final T evalAfterValue);
27  	/**
28  	 * Adds the node as dependent on all leaf nodes (at the time of adding), meaning all leaf nodes would be evaluated first and then the given node
29  	 * 
30  	 * @param nodeValue
31  	 */
32  	void addAsDependentOnAllLeafNodes(final T nodeValue);
33  	/**
34  	 * Adds the node as dependency to all initial nodes (at the time of adding), meaning this given node would be evaluated first and then all initial nodes would run in parallel
35  	 * 
36  	 * @param nodeValue
37  	 */
38  	void addAsDependencyToAllInitialNodes(final T nodeValue);
39  	/**
40  	 * Kicks off the execution of the nodes based on the dependency graph constructed, using {@code addDepen***} apis
41  	 * 
42  	 * @param behavior
43  	 */
44  	void execute(final ExecutionBehavior behavior);
45  	
46  	/**
47  	 * Prints the graph into the writer
48  	 * 
49  	 * @param writer
50  	 */
51  	void print(final Writer writer);
52  	
53  	/**
54  	 * Defines the execution behavior of the tasks
55  	 *   <ul>
56  	 * 	   <li>
57  	 * 			<code>TERMINATING </code> : Whole tasks execution would come to an end after the execution is thrown
58  	 * 	   </li>
59  	 * 		<li>
60  	 * 			<code>NON_TERMINATING</code> : Tasks execution wont come to halt after an exception is thrown out of task
61  	 * 		</li>
62  	 * 		<li>
63  	 * 			<code>RETRY_ONCE_TERMINATING</code> : A retry would be attempted after an exception is thrown, and then if the execption is thrown again, the tasks execution would stop
64  	 * 		</li>
65  	 * 
66  	 * </ul>
67  	 * 
68  	 * @author Nadeem Mohammad
69  	 *
70  	 */
71  	enum ExecutionBehavior {
72  		TERMINATING, NON_TERMINATING, RETRY_ONCE_TERMINATING;
73  	}
74  }