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.core;
19 /**
20 * A Task Provider provides Tasks to be executed, when it comes to execution
21 * @author Nadeem Mohammad
22 *
23 * @param <T> Type of Node/Task ID
24 * @param <R> Type of Node/Task result
25 */
26
27 public interface TaskProvider <T extends Comparable<T>, R> {
28 /**
29 * Given the node id, returns the task to be executed, while building graph only the node ids are required, when it comes to execution Task objects would be constructed
30 *
31 * @param id
32 * @return @Task
33 */
34 public Task<T, R> provid(final T id);
35
36 /**
37 * Represent a unit of execution in Dexecutor framework
38 *
39 * @author Nadeem Mohammad
40 *
41 * @param <T> Type of Node/Task ID
42 * @param <R> Type of Node/Task result
43 */
44 public abstract class Task<T, R> {
45 /**
46 * Framework would call this method, when it comes for tasks to be executed.
47 * @return the result of task execution
48 */
49 public abstract R execute();
50 /**
51 * When using retry behavior, execution error should not be considered until the last retry, this would define when execution error should be considered
52 */
53 private boolean considerExecutionError = true;
54 /**
55 *
56 * @return whether execution error should be considered or not
57 */
58 public final boolean shouldConsiderExecutionError() {
59 return this.considerExecutionError;
60 }
61 /**
62 *
63 * @param considerExecutionError
64 */
65 void setConsiderExecutionError(boolean considerExecutionError) {
66 this.considerExecutionError = considerExecutionError;
67 }
68 /**
69 * Defines whether or not this task should be executed
70 *
71 * @param parentResults
72 *
73 * @return {@code true} If this task should be executed
74 * {@code false} If the task should be skipped
75 */
76 public boolean shouldExecute(final ExecutionResults<T, R> parentResults) {
77 return true;
78 }
79 }
80 }