01: package org.objectweb.celtix.bindings;
02:
03: import java.util.concurrent.ExecutionException;
04: import java.util.concurrent.Future;
05: import java.util.concurrent.TimeUnit;
06: import java.util.concurrent.TimeoutException;
07:
08: import org.objectweb.celtix.context.InputStreamMessageContext;
09: import org.objectweb.celtix.context.ObjectMessageContext;
10: import org.objectweb.celtix.handlers.HandlerInvoker;
11:
12: public class AsyncFuture implements Future<ObjectMessageContext> {
13:
14: private final Future<InputStreamMessageContext> futureInputStreamMsgContext;
15: private final AbstractClientBinding absClientBinding;
16: private final HandlerInvoker handlerInvoker;
17: private final DataBindingCallback callback;
18: private final ObjectMessageContext context;
19:
20: public AsyncFuture(
21: Future<InputStreamMessageContext> fInputStreamMsgContext,
22: AbstractClientBinding aClientBinding,
23: DataBindingCallback cback, HandlerInvoker hInvoker,
24: ObjectMessageContext ctx) {
25: futureInputStreamMsgContext = fInputStreamMsgContext;
26: absClientBinding = aClientBinding;
27: handlerInvoker = hInvoker;
28: callback = cback;
29: context = ctx;
30: }
31:
32: public synchronized ObjectMessageContext get()
33: throws InterruptedException, ExecutionException {
34: InputStreamMessageContext ins = futureInputStreamMsgContext
35: .get();
36: return absClientBinding.getObjectMessageContextAsync(ins,
37: handlerInvoker, callback, context);
38: }
39:
40: public boolean cancel(boolean mayInterruptIfRunning) {
41: return futureInputStreamMsgContext
42: .cancel(mayInterruptIfRunning);
43: }
44:
45: public ObjectMessageContext get(long timeout, TimeUnit unit)
46: throws InterruptedException, ExecutionException,
47: TimeoutException {
48: InputStreamMessageContext ins = futureInputStreamMsgContext
49: .get(timeout, unit);
50: return absClientBinding.getObjectMessageContextAsync(ins,
51: handlerInvoker, callback, context);
52: }
53:
54: public boolean isCancelled() {
55: return futureInputStreamMsgContext.isCancelled();
56: }
57:
58: public boolean isDone() {
59: return futureInputStreamMsgContext.isDone();
60: }
61:
62: }
|