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.task;
16  
17  /**
18   * A {@link Runnable} implementation and wrapper that supports a call back for the execution of a
19   * task.
20   * 
21   * @author Zardi (https://sourceforge.net/users/daniel_zardi)
22   * @version 1.0.0
23   * @since 1.0.0
24   */
25  public class NotifiableTask implements Runnable {
26  
27  	/**
28  	 * The task that will be monitored for execution.
29  	 */
30  	private final Runnable task;
31  
32  	/**
33  	 * The call back that will be executed after the task execution.
34  	 */
35  	private final Runnable callback;
36  
37  	/**
38  	 * Constructs a new NotifiableTask with the given task and call back.
39  	 * 
40  	 * @param task
41  	 *            The task to be monitored.
42  	 * @param callback
43  	 *            The call back to be invoked after the task completion.
44  	 * @since 1.0.0
45  	 */
46  	public NotifiableTask(Runnable task, Runnable callback) {
47  		this.task = task;
48  		this.callback = callback;
49  	}
50  
51  	/** {@inheritDoc} */
52  	public void run() {
53  		task.run();
54  		callback.run();
55  	}
56  
57  }