01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.jaxws;
19:
20: import java.util.Map;
21: import java.util.concurrent.ExecutionException;
22: import java.util.concurrent.Future;
23: import java.util.concurrent.TimeUnit;
24: import java.util.concurrent.TimeoutException;
25:
26: import javax.xml.ws.Response;
27:
28: public class AsyncResponse<T> implements Response<T> {
29:
30: private final Future<T> obj;
31: private T result;
32: private Class<T> cls;
33:
34: public AsyncResponse(Future<T> object, Class<T> c) {
35: obj = object;
36: cls = c;
37: }
38:
39: public boolean cancel(boolean interrupt) {
40: return obj.cancel(interrupt);
41: }
42:
43: public boolean isCancelled() {
44: return obj.isCancelled();
45: }
46:
47: public boolean isDone() {
48: return obj.isDone();
49: }
50:
51: public synchronized T get() throws InterruptedException,
52: ExecutionException {
53: if (result == null) {
54: result = cls.cast(obj.get());
55: }
56: return result;
57: }
58:
59: public T get(long timeout, TimeUnit unit)
60: throws InterruptedException, ExecutionException,
61: TimeoutException {
62: if (result == null) {
63: result = cls.cast(obj.get(timeout, unit));
64: }
65: return result;
66: }
67:
68: public Map<String, Object> getContext() {
69: return null;
70: }
71:
72: }
|