View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.util.concurrent.processing;
20  
21  import java.util.concurrent.Callable;
22  import java.util.concurrent.ExecutorService;
23  
24  /**
25   * A processable executor uses a {@link ExecutorService} to submit
26   * given tasks and returns a {@link MCRProcessableSupplier}.
27   * 
28   * @author Matthias Eichner
29   */
30  public interface MCRProcessableExecutor {
31  
32      /**
33       * Submits the runnable with priority zero (executed at last). 
34       * 
35       * @param runnable the runnable to submit
36       * @return a {@link MCRProcessableSupplier} with no result
37       */
38      default MCRProcessableSupplier<?> submit(Runnable runnable) {
39          return submit(runnable, 0);
40      }
41  
42      /**
43       * Submits the runnable with the given priority. 
44       * 
45       * @param runnable the runnable to submit
46       * @return a {@link MCRProcessableSupplier} with no result
47       */
48      default MCRProcessableSupplier<?> submit(Runnable runnable, int priority) {
49          return submit(MCRProcessableFactory.progressableCallable(runnable), priority);
50      }
51  
52      /**
53       * Submits the callable with priority zero (executed at last). 
54       * 
55       * @param callable the callable to submit
56       * @return a {@link MCRProcessableSupplier} with the result of R
57       */
58      default <R> MCRProcessableSupplier<R> submit(Callable<R> callable) {
59          return submit(callable, 0);
60      }
61  
62      /**
63       * Submits the callable with the given priority.  
64       * 
65       * @param callable the callable to submit
66       * @return a {@link MCRProcessableSupplier} with the result of R
67       */
68      <R> MCRProcessableSupplier<R> submit(Callable<R> callable, int priority);
69  
70      /**
71       * Returns the underlying executor service.
72       * 
73       * <p><b>
74       * You should not submit task to this thread pool directly. Use the submit
75       * methods of this class instead.
76       * </b></p>
77       * 
78       * @return the thread pool.
79       */
80      ExecutorService getExecutor();
81  }