01: /*
02: * Copyright 2004-2006 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:
17: package org.compass.core.executor;
18:
19: import java.util.concurrent.ExecutionException;
20: import java.util.concurrent.Future;
21: import java.util.concurrent.TimeUnit;
22: import java.util.concurrent.TimeoutException;
23:
24: /**
25: * A dummy future representing a result that was already processed (with a
26: * result or an exception).
27: *
28: * @author kimchy
29: */
30: class DummyFuture<T> implements Future<T> {
31:
32: private Exception e;
33:
34: private T result;
35:
36: public DummyFuture(Exception e) {
37: this .e = e;
38: }
39:
40: public DummyFuture(T result) {
41: this .result = result;
42: }
43:
44: public boolean cancel(boolean mayInterruptIfRunning) {
45: return false;
46: }
47:
48: public T get() throws InterruptedException, ExecutionException {
49: if (e != null) {
50: throw new ExecutionException(e);
51: }
52: return result;
53: }
54:
55: public T get(long timeout, TimeUnit unit)
56: throws InterruptedException, ExecutionException,
57: TimeoutException {
58: return get();
59: }
60:
61: public boolean isCancelled() {
62: return false;
63: }
64:
65: public boolean isDone() {
66: return true;
67: }
68: }
|