01 /*
02 * Copyright 2010-2012 the original author or authors.
03 *
04 * Licensed under the Apache License, Version 2.0 (the "License");
05 * you may not use this file except in compliance with the License.
06 * You may obtain a copy of the License at
07 *
08 * http://www.apache.org/licenses/LICENSE-2.0
09 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package griffon.core;
17
18 import groovy.lang.Closure;
19
20 import java.util.concurrent.Callable;
21 import java.util.concurrent.ExecutorService;
22 import java.util.concurrent.Future;
23
24 /**
25 * Base contract for classes that can perform tasks in different threads following
26 * the conventions set by the application.
27 *
28 * @author Andres Almiray
29 * @since 0.9.3
30 */
31 public interface ThreadingHandler {
32 /**
33 * True if the current thread is the UI thread.
34 */
35 boolean isUIThread();
36
37 /**
38 * Executes a code block asynchronously on the UI thread.
39 *
40 * @deprecated use #execInsideUIAsync() instead
41 */
42 @Deprecated
43 void execAsync(Runnable runnable);
44
45 /**
46 * Executes a code block synchronously on the UI thread.
47 *
48 * @deprecated use #execInsideUIsync() instead
49 */
50 @Deprecated
51 void execSync(Runnable runnable);
52
53 /**
54 * Executes a code block outside of the UI thread.
55 *
56 * @deprecated use #execOutsideUI() instead
57 */
58 @Deprecated
59 void execOutside(Runnable runnable);
60
61 /**
62 * Executes a code block asynchronously on the UI thread.
63 */
64 void execInsideUIAsync(Runnable runnable);
65
66 /**
67 * Executes a code block synchronously on the UI thread.
68 */
69 void execInsideUISync(Runnable runnable);
70
71 /**
72 * Executes a code block outside of the UI thread.
73 */
74 void execOutsideUI(Runnable runnable);
75
76 /**
77 * Executes a code block as a Future on an ExecutorService.
78 */
79 Future execFuture(ExecutorService executorService, Closure closure);
80
81 /**
82 * Executes a code block as a Future on a default ExecutorService.
83 */
84 Future execFuture(Closure closure);
85
86 /**
87 * Executes a code block as a Future on an ExecutorService.
88 */
89 Future execFuture(ExecutorService executorService, Callable callable);
90
91 /**
92 * Executes a code block as a Future on a default ExecutorService.
93 */
94 Future execFuture(Callable callable);
95 }
|