Make ChannelFutureNotifier accept multiple ChannelFutures

This commit is contained in:
Trustin Lee 2012-12-14 20:09:40 +09:00
parent eb23c9d27c
commit d8c569a71b

View File

@ -16,22 +16,47 @@
package io.netty.channel; package io.netty.channel;
/** /**
* ChannelFutureListener implementation which takes another ChannelFuture and notifies it * ChannelFutureListener implementation which takes other {@link ChannelFuture}(s) and notifies them on completion.
* once the operationComplete method was called.
*/ */
public final class ChannelFutureNotifier implements ChannelFutureListener { public final class ChannelFutureNotifier implements ChannelFutureListener {
private final ChannelFuture future;
public ChannelFutureNotifier(ChannelFuture future) { private final ChannelFuture[] futures;
this.future = future;
public ChannelFutureNotifier(ChannelFuture... futures) {
if (futures == null) {
throw new NullPointerException("futures");
}
this.futures = futures.clone();
} }
@Override @Override
public void operationComplete(ChannelFuture cf) throws Exception { public void operationComplete(ChannelFuture cf) throws Exception {
if (cf.isSuccess()) { if (cf.isSuccess()) {
future.setSuccess(); for (ChannelFuture f: futures) {
} else { if (f == null) {
future.setFailure(cf.cause()); break;
}
f.setSuccess();
}
return;
}
if (cf.isCancelled()) {
for (ChannelFuture f: futures) {
if (f == null) {
break;
}
f.cancel();
}
return;
}
Throwable cause = cf.cause();
for (ChannelFuture f: futures) {
if (f == null) {
break;
}
f.setFailure(cause);
} }
} }
} }