View Javadoc
1   package com.github.dexecutor.executor;
2   
3   import java.util.concurrent.ExecutorService;
4   
5   import com.github.dexecutor.executor.graph.CyclicValidator;
6   import com.github.dexecutor.executor.graph.LevelOrderTraversar;
7   import com.github.dexecutor.executor.graph.Traversar;
8   import com.github.dexecutor.executor.graph.Validator;
9   import static com.github.dexecutor.executor.support.Preconditions.*;
10  
11  /**
12   * <p>Configuration Object for Dexecutor framework. At a minimum it needs {@code ExecutorService} and {@code TaskProvider}, rest are optional and takes default values</p>
13   * <p>This provides way to hook in your own {@code Validator} and {@code Traversar}</p>
14   * 
15   * @author Nadeem Mohammad
16   *
17   * @param <T>
18   */
19  public class DependentTasksExecutorConfig<T extends Comparable<T>> {
20  	/**
21  	 * executorService is the main platform on which tasks are executed
22  	 */
23  	private ExecutorService executorService;
24  	/**
25  	 * When it comes to task execution, task provider would be consulted to provide task objects for execution
26  	 */
27  	private TaskProvider<T> taskProvider;
28  	/**
29  	 * Validator for validating the consturcted graph, defaults to detecting Cyclic checks
30  	 */
31  	private Validator<T> validator = new CyclicValidator<T>();
32  	/**
33  	 * Traversar used to traverse the graph while printing it on a Writer
34  	 */
35  	private Traversar<T> traversar = new LevelOrderTraversar<T>();
36  	/**
37  	 * Construct the object with mandatory params, rest are optional
38  	 * @param executorService
39  	 * @param taskProvider
40  	 */
41  	public DependentTasksExecutorConfig(final ExecutorService executorService, final TaskProvider<T> taskProvider) {
42  		this.executorService = executorService;
43  		this.taskProvider = taskProvider;
44  	}
45  
46  	void validate() {
47  		checkNotNull(this.executorService, "Executer Service should not be null");
48  		checkNotNull(this.taskProvider, "Task Provider should not be null");
49  		checkNotNull(this.validator, "Validator should not be null");
50  		checkNotNull(this.traversar, "Traversar should not be null");
51  	}
52  
53  	ExecutorService getExecutorService() {
54  		return executorService;
55  	}
56  
57  	TaskProvider<T> getTaskProvider() {
58  		return taskProvider;
59  	}
60  
61  	Validator<T> getValidator() {
62  		return validator;
63  	}
64  	/**
65  	 * change the validator to that of specified
66  	 * @param validator
67  	 */
68  	public void setValidator(final Validator<T> validator) {
69  		this.validator = validator;
70  	}
71  	Traversar<T> getTraversar() {
72  		return traversar;
73  	}
74  	/**
75  	 * Change the traversar to that of specified
76  	 * @param traversar
77  	 */
78  	public void setTraversar(final Traversar<T> traversar) {
79  		this.traversar = traversar;
80  	}
81  }