Mark final, add javadocs, add checks

This commit is contained in:
Norman Maurer 2012-12-20 16:13:26 +01:00
parent d2060ee3f1
commit 5d6d849acd

View File

@ -18,12 +18,23 @@ package io.netty.channel;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Queue; import java.util.Queue;
public class ChannelFlushFutureNotifier { public final class ChannelFlushFutureNotifier {
private long writeCounter; private long writeCounter;
private final Queue<FlushCheckpoint> flushCheckpoints = new ArrayDeque<FlushCheckpoint>(); private final Queue<FlushCheckpoint> flushCheckpoints = new ArrayDeque<FlushCheckpoint>();
/**
* Add a {@link ChannelFuture} to this {@link ChannelFlushFutureNotifier} which will be notified after the given
* pendingDataSize was reached.
*/
public void addFlushFuture(ChannelFuture future, int pendingDataSize) { public void addFlushFuture(ChannelFuture future, int pendingDataSize) {
if (future == null) {
throw new NullPointerException("future");
}
if (pendingDataSize < 0) {
throw new IllegalArgumentException("pendingDataSize must be >= 0 but was" + pendingDataSize);
}
long checkpoint = writeCounter + pendingDataSize; long checkpoint = writeCounter + pendingDataSize;
if (future instanceof FlushCheckpoint) { if (future instanceof FlushCheckpoint) {
FlushCheckpoint cp = (FlushCheckpoint) future; FlushCheckpoint cp = (FlushCheckpoint) future;
@ -34,14 +45,45 @@ public class ChannelFlushFutureNotifier {
} }
} }
/**
* Increase the current write counter by the given delta
*/
public void increaseWriteCounter(long delta) { public void increaseWriteCounter(long delta) {
if (delta < 0) {
throw new IllegalArgumentException("delta must be >= 0 but was" + delta);
}
writeCounter += delta; writeCounter += delta;
} }
/**
* Return the current write counter of this {@link ChannelFlushFutureNotifier}
*/
public long writeCounter() {
return writeCounter;
}
/**
* Notify all {@link ChannelFuture}s that were registered with {@link #addFlushFuture(ChannelFuture, int)} and
* their pendingDatasize is smaller after the the current writeCounter returned by {@link #writeCounter()}.
*
* After a {@link ChannelFuture} was notified it will be removed from this {@link ChannelFlushFutureNotifier} and
* so not receive anymore notificiation.
*/
public void notifyFlushFutures() { public void notifyFlushFutures() {
notifyFlushFutures0(null); notifyFlushFutures0(null);
} }
/**
* Notify all {@link ChannelFuture}s that were registered with {@link #addFlushFuture(ChannelFuture, int)} and
* their pendingDatasize isis smaller then the current writeCounter returned by {@link #writeCounter()}.
*
* After a {@link ChannelFuture} was notified it will be removed from this {@link ChannelFlushFutureNotifier} and
* so not receive anymore notificiation.
*
* The rest of the remaining {@link ChannelFuture}s will be failed with the given {@link Throwable}.
*
* So after this operation this {@link ChannelFutureListener} is empty.
*/
public void notifyFlushFutures(Throwable cause) { public void notifyFlushFutures(Throwable cause) {
notifyFlushFutures(); notifyFlushFutures();
for (;;) { for (;;) {
@ -53,6 +95,22 @@ public class ChannelFlushFutureNotifier {
} }
} }
/**
* Notify all {@link ChannelFuture}s that were registered with {@link #addFlushFuture(ChannelFuture, int)} and
* their pendingDatasize is smaller then the current writeCounter returned by {@link #writeCounter()} using
* the given cause1.
*
* After a {@link ChannelFuture} was notified it will be removed from this {@link ChannelFlushFutureNotifier} and
* so not receive anymore notificiation.
*
* The rest of the remaining {@link ChannelFuture}s will be failed with the given {@link Throwable}.
*
* So after this operation this {@link ChannelFutureListener} is empty.
*
* @param cause1 the {@link Throwable} which will be used to fail all of the {@link ChannelFuture}s whichs
* pendingDataSize is smaller then the current writeCounter returned by {@link #writeCounter()}
* @param cause2 the {@link Throwable} which will be used to fail the remaining {@link ChannelFuture}s
*/
public void notifyFlushFutures(Throwable cause1, Throwable cause2) { public void notifyFlushFutures(Throwable cause1, Throwable cause2) {
notifyFlushFutures0(cause1); notifyFlushFutures0(cause1);
for (;;) { for (;;) {