Add methods that add/remove multiple ChannelFutureListeners to ChannelFuture

- Fixes #811
This commit is contained in:
Trustin Lee 2012-12-14 12:45:43 +09:00
parent 1f72e53af3
commit 02a6e85feb
4 changed files with 79 additions and 0 deletions

View File

@ -250,6 +250,14 @@ public interface ChannelFuture extends Future<Void> {
*/ */
ChannelFuture addListener(ChannelFutureListener listener); ChannelFuture addListener(ChannelFutureListener listener);
/**
* Adds the specified listeners to this future. The
* specified listeners are notified when this future is
* {@linkplain #isDone() done}. If this future is already
* completed, the specified listeners are notified immediately.
*/
ChannelFuture addListeners(ChannelFutureListener... listeners);
/** /**
* Removes the specified listener from this future. * Removes the specified listener from this future.
* The specified listener is no longer notified when this * The specified listener is no longer notified when this
@ -259,6 +267,15 @@ public interface ChannelFuture extends Future<Void> {
*/ */
ChannelFuture removeListener(ChannelFutureListener listener); ChannelFuture removeListener(ChannelFutureListener listener);
/**
* Removes the specified listeners from this future.
* The specified listeners are no longer notified when this
* future is {@linkplain #isDone() done}. If the specified
* listeners are not associated with this future, this method
* does nothing and returns silently.
*/
ChannelFuture removeListeners(ChannelFutureListener... listeners);
/** /**
* Waits for this future until it is done, and rethrows the cause of the failure if this future * Waits for this future until it is done, and rethrows the cause of the failure if this future
* failed. If the cause of the failure is a checked exception, it is wrapped with a new * failed. If the cause of the failure is a checked exception, it is wrapped with a new

View File

@ -46,12 +46,32 @@ public abstract class CompleteChannelFuture implements ChannelFuture {
return this; return this;
} }
@Override
public ChannelFuture addListeners(ChannelFutureListener... listeners) {
if (listeners == null) {
throw new NullPointerException("listeners");
}
for (ChannelFutureListener l: listeners) {
if (l == null) {
break;
}
DefaultChannelFuture.notifyListener(this, l);
}
return this;
}
@Override @Override
public ChannelFuture removeListener(ChannelFutureListener listener) { public ChannelFuture removeListener(ChannelFutureListener listener) {
// NOOP // NOOP
return this; return this;
} }
@Override
public ChannelFuture removeListeners(ChannelFutureListener... listeners) {
// NOOP
return this;
}
@Override @Override
public ChannelFuture await() throws InterruptedException { public ChannelFuture await() throws InterruptedException {
if (Thread.interrupted()) { if (Thread.interrupted()) {

View File

@ -143,6 +143,21 @@ public class DefaultChannelFuture extends FlushCheckpoint implements ChannelFutu
return this; return this;
} }
@Override
public ChannelFuture addListeners(ChannelFutureListener... listeners) {
if (listeners == null) {
throw new NullPointerException("listeners");
}
for (ChannelFutureListener l: listeners) {
if (l == null) {
break;
}
addListener(l);
}
return this;
}
@Override @Override
public ChannelFuture removeListener(ChannelFutureListener listener) { public ChannelFuture removeListener(ChannelFutureListener listener) {
if (listener == null) { if (listener == null) {
@ -170,6 +185,21 @@ public class DefaultChannelFuture extends FlushCheckpoint implements ChannelFutu
return this; return this;
} }
@Override
public ChannelFuture removeListeners(ChannelFutureListener... listeners) {
if (listeners == null) {
throw new NullPointerException("listeners");
}
for (ChannelFutureListener l: listeners) {
if (l == null) {
break;
}
removeListener(l);
}
return this;
}
@Override @Override
public ChannelFuture sync() throws InterruptedException { public ChannelFuture sync() throws InterruptedException {
await(); await();

View File

@ -41,12 +41,24 @@ public class VoidChannelFuture implements ChannelFuture.Unsafe {
return this; return this;
} }
@Override
public ChannelFuture addListeners(final ChannelFutureListener... listeners) {
fail();
return this;
}
@Override @Override
public ChannelFuture removeListener(ChannelFutureListener listener) { public ChannelFuture removeListener(ChannelFutureListener listener) {
// NOOP // NOOP
return this; return this;
} }
@Override
public ChannelFuture removeListeners(ChannelFutureListener... listeners) {
// NOOP
return this;
}
@Override @Override
public ChannelFuture await() throws InterruptedException { public ChannelFuture await() throws InterruptedException {
if (Thread.interrupted()) { if (Thread.interrupted()) {