1 package org.apache.mina.common;
2
3 import java.util.concurrent.atomic.AtomicInteger;
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public class CompositeIoFuture<E extends IoFuture> extends DefaultIoFuture {
18
19 private final NotifyingListener listener = new NotifyingListener();
20 private final AtomicInteger unnotified = new AtomicInteger();
21 private volatile boolean constructionFinished;
22
23 public CompositeIoFuture(Iterable<E> children) {
24 super(null);
25
26 for (E f: children) {
27 f.addListener(listener);
28 unnotified.incrementAndGet();
29 }
30
31 constructionFinished = true;
32 if (unnotified.get() == 0) {
33 setValue(true);
34 }
35 }
36
37 private class NotifyingListener implements IoFutureListener<IoFuture> {
38 public void operationComplete(IoFuture future) {
39 if (unnotified.decrementAndGet() == 0 && constructionFinished) {
40 setValue(true);
41 }
42 }
43 }
44 }