Last change
on this file since 193 was
193,
checked in by Maciej Komosinski, 10 years ago
|
Set svn:eol-style native for all textual files
|
-
Property svn:eol-style set to
native
|
File size:
1.0 KB
|
Line | |
---|
1 | package com.framsticks.util.dispatching; |
---|
2 | |
---|
3 | import com.framsticks.util.FramsticksException; |
---|
4 | |
---|
5 | public class DispatchingFuture<C, T> extends FutureHandler<T> { |
---|
6 | |
---|
7 | protected final Dispatcher<? super C> dispatcher; |
---|
8 | protected final FutureHandler<T> future; |
---|
9 | |
---|
10 | /** |
---|
11 | * @param dispatcher |
---|
12 | * @param future |
---|
13 | */ |
---|
14 | public DispatchingFuture(Dispatcher<? super C> dispatcher, FutureHandler<T> future) { |
---|
15 | this.dispatcher = dispatcher; |
---|
16 | this.future = future; |
---|
17 | } |
---|
18 | |
---|
19 | @Override |
---|
20 | public void handle(final FramsticksException exception) { |
---|
21 | Dispatching.dispatchIfNotActive(dispatcher, new RunAt<C>(ThrowExceptionHandler.getInstance()) { |
---|
22 | @Override |
---|
23 | protected void runAt() { |
---|
24 | future.handle(exception); |
---|
25 | } |
---|
26 | }); |
---|
27 | } |
---|
28 | |
---|
29 | @Override |
---|
30 | protected void result(final T result) { |
---|
31 | Dispatching.dispatchIfNotActive(dispatcher, new RunAt<C>(future) { |
---|
32 | @Override |
---|
33 | protected void runAt() { |
---|
34 | future.pass(result); |
---|
35 | } |
---|
36 | }); |
---|
37 | } |
---|
38 | |
---|
39 | public static <Ca, Ta> FutureHandler<Ta> create(Dispatcher<Ca> dispatcher, FutureHandler<Ta> future) { |
---|
40 | return new DispatchingFuture<Ca, Ta>(dispatcher, future); |
---|
41 | } |
---|
42 | |
---|
43 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.