01 /*
02 * Copyright 2008-2014 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 org.codehaus.griffon.runtime.core;
17
18 import griffon.core.GriffonApplication;
19 import griffon.core.LifecycleHandler;
20
21 import javax.annotation.Nonnull;
22 import javax.inject.Inject;
23 import java.util.concurrent.Callable;
24 import java.util.concurrent.ExecutorService;
25 import java.util.concurrent.Future;
26
27 import static java.util.Objects.requireNonNull;
28
29 /**
30 * Base implementation of the {@code LifecycleHandler} interface.
31 *
32 * @author Andres Almiray
33 * @since 2.0.0
34 */
35 public abstract class AbstractLifecycleHandler implements LifecycleHandler {
36 private final GriffonApplication application;
37
38 @Inject
39 public AbstractLifecycleHandler(@Nonnull GriffonApplication application) {
40 this.application = requireNonNull(application, "Argument 'application' must not be null");
41 }
42
43 @Nonnull
44 protected GriffonApplication getApplication() {
45 return application;
46 }
47
48 @Override
49 public boolean isUIThread() {
50 return application.getUIThreadManager().isUIThread();
51 }
52
53 @Override
54 @Nonnull
55 public <R> Future<R> runFuture(@Nonnull Callable<R> callable) {
56 return application.getUIThreadManager().runFuture(callable);
57 }
58
59 @Override
60 @Nonnull
61 public <R> Future<R> runFuture(@Nonnull ExecutorService executorService, @Nonnull Callable<R> callable) {
62 return application.getUIThreadManager().runFuture(executorService, callable);
63 }
64
65 @Override
66 public void runInsideUIAsync(@Nonnull Runnable runnable) {
67 application.getUIThreadManager().runInsideUIAsync(runnable);
68 }
69
70 @Override
71 public void runInsideUISync(@Nonnull Runnable runnable) {
72 application.getUIThreadManager().runInsideUISync(runnable);
73 }
74
75 @Override
76 public void runOutsideUI(@Nonnull Runnable runnable) {
77 application.getUIThreadManager().runOutsideUI(runnable);
78 }
79 }
|