View Javadoc

1   /*
2    * This file is part of AceLogger.
3    * 
4    * AceLogger is free software: you can redistribute it and/or modify it under the terms of the GNU
5    * Lesser General Public License as published by the Free Software Foundation, either version 3 of
6    * the License, or (at your option) any later version.
7    * 
8    * AceLogger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9    * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10   * Lesser General Public License for more details.
11   * 
12   * You should have received a copy of the GNU Lesser General Public License along with AceLogger.
13   * If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
14   */
15  package net.sourceforge.acelogger.execution.manager;
16  
17  import java.util.List;
18  
19  import net.sourceforge.acelogger.Identifiable;
20  
21  /**
22   * A interface providing task execution abstraction.
23   * 
24   * @author Zardi (https://sourceforge.net/users/daniel_zardi)
25   * @version 1.0.0
26   * @since 1.0.0
27   */
28  public interface ExecutorManager extends Identifiable {
29  
30  	/**
31  	 * Orders the proper shutdown of this executor manager, this is accomplished in most of the
32  	 * implementations by waiting all pending tasks or a given timeout.
33  	 * 
34  	 * @return True if the executor shutdown process was successful; False otherwise.
35  	 * @since 1.0.0
36  	 */
37  	public boolean orderProperShutdown();
38  
39  	/**
40  	 * Waits the execution of pending tasks in this executor manager. This method must be called
41  	 * after ordering a proper shutdown.
42  	 * 
43  	 * @param terminationTimeout
44  	 *            The maximum time (in ms) to wait for remaining tasks to execute.
45  	 * @return True if the executor finished processing all of it's tasks; False if timeout was
46  	 *         reached during the wait.
47  	 * @since 1.0.0~
48  	 * @see ExecutorManager#orderProperShutdown()
49  	 */
50  	public boolean awaitTermination(long terminationTimeout);
51  
52  	/**
53  	 * Terminates this executor manager, return a list of tasks that were not executed after a
54  	 * proper shutdown was ordered. This method should be called preferably after waiting for the
55  	 * tasks to execute.
56  	 * 
57  	 * @return A list containing the tasks pending execution.
58  	 * @since 1.0.0
59  	 * @see ExecutorManager#orderProperShutdown()
60  	 * @see ExecutorManager#awaitTermination(long)
61  	 */
62  	public List<Runnable> terminateAndRetrieveTasks();
63  
64  	/**
65  	 * Returns true if this executor manager has ended its execution scheduling.
66  	 * 
67  	 * @return True if the executor manager was shutdown; False otherwise.
68  	 * @since 1.0.0
69  	 */
70  	public boolean isTerminated();
71  
72  	/**
73  	 * Executes the given command within this executor. This method should block until the command
74  	 * execution or not, this will depend on the implementation.
75  	 * 
76  	 * @param command
77  	 *            The task to be executed.
78  	 * @since 1.0.0
79  	 */
80  	public void execute(Runnable command);
81  
82  	/**
83  	 * Executes the given commands within this executor, one by one. This method should block until
84  	 * the command execution or not, this will depend on the implementation.
85  	 * 
86  	 * @param commands
87  	 *            A list of tasks to be executed.
88  	 * @since 1.0.0
89  	 */
90  	public void executeAll(List<Runnable> commands);
91  
92  }