1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.github.dexecutor.executor; 19 20 import java.io.Writer; 21 22 /** 23 * Main Interface for Dexecutor framework, It provides api to build the graph and and to kick off the execution. 24 * 25 * @author Nadeem Mohammad 26 * 27 * @see {@link DefaultDependentTasksExecutor} 28 * 29 * @param <T> Type of Node/Task ID 30 * @param <R> Type of Node/Task result 31 */ 32 public interface DependentTasksExecutor<T extends Comparable<T>> { 33 /** 34 * Add a node as independent, it does not require any dependent node 35 * 36 * @param nodeValue 37 */ 38 void addIndependent(final T nodeValue); 39 /** 40 * <p>Add Two dependent nodes into the graph, creating the nodes if not already present </p> 41 * <p><code>evalFirstValue </code> would be executed first and then <code> evalAfterValue </code> </p> 42 * 43 * @param evalFirstValue 44 * @param evalAfterValue 45 */ 46 void addDependency(final T evalFirstValue, final T evalAfterValue); 47 /** 48 * 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 49 * 50 * @param nodeValue 51 */ 52 void addAsDependentOnAllLeafNodes(final T nodeValue); 53 /** 54 * 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 55 * 56 * @param nodeValue 57 */ 58 void addAsDependencyToAllInitialNodes(final T nodeValue); 59 /** 60 * Kicks off the execution of the nodes based on the dependency graph constructed, using {@code addDepen***} apis 61 * 62 * @param behavior 63 */ 64 void execute(final ExecutionBehavior behavior); 65 66 /** 67 * Prints the graph into the writer 68 * 69 * @param writer 70 */ 71 void print(final Writer writer); 72 73 /** 74 * Defines the execution behavior of the tasks 75 * <ul> 76 * <li> 77 * <code>TERMINATING </code> : Whole tasks execution would come to an end after the execution is thrown 78 * </li> 79 * <li> 80 * <code>NON_TERMINATING</code> : Tasks execution wont come to halt after an exception is thrown out of task 81 * </li> 82 * <li> 83 * <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 84 * </li> 85 * 86 * </ul> 87 * 88 * @author Nadeem Mohammad 89 * 90 */ 91 enum ExecutionBehavior { 92 TERMINATING, NON_TERMINATING, RETRY_ONCE_TERMINATING; 93 } 94 }