[#1058] Add Channel/ChannelHandlerContext/ChannelPipeline.isWritable()

This commit is contained in:
Norman Maurer 2013-02-17 21:13:03 +01:00
parent 1c6ed9b2ce
commit 4e36fbca58
6 changed files with 41 additions and 0 deletions

View File

@ -133,6 +133,11 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
}); });
} }
@Override
public boolean isWritable() {
return pipeline.isWritable();
}
@Override @Override
public final Integer id() { public final Integer id() {
return id; return id;

View File

@ -108,6 +108,11 @@ public interface Channel extends AttributeMap, ChannelOutboundInvoker, ChannelPr
*/ */
boolean isActive(); boolean isActive();
/**
* Return {@code true} if the outbound buffer of the {@link Channel} is writable.
*/
boolean isWritable();
/** /**
* Return the {@link ChannelMetadata} of the {@link Channel} which describe the nature of the {@link Channel}. * Return the {@link ChannelMetadata} of the {@link Channel} which describe the nature of the {@link Channel}.
*/ */

View File

@ -128,6 +128,12 @@ public interface ChannelHandlerContext
extends AttributeMap, ChannelPropertyAccess, extends AttributeMap, ChannelPropertyAccess,
ChannelInboundInvoker, ChannelOutboundInvoker { ChannelInboundInvoker, ChannelOutboundInvoker {
/**
* Return {@link true} if the {@link ChannelHandlerContext} is writable, which means if the outbound buffer of
* the next in the {@link ChannelPipeline} is writable.
*/
boolean isWritable();
/** /**
* Return the {@link Channel} which is bound to the {@link ChannelHandlerContext}. * Return the {@link Channel} which is bound to the {@link ChannelHandlerContext}.
*/ */

View File

@ -732,6 +732,11 @@ public interface ChannelPipeline extends ChannelInboundInvoker, ChannelOutboundI
*/ */
Map<String, ChannelHandler> toMap(); Map<String, ChannelHandler> toMap();
/**
* Return {@code true} if the outbound buffer is writable.
*/
boolean isWritable();
@Override @Override
ChannelPipeline fireChannelRegistered(); ChannelPipeline fireChannelRegistered();

View File

@ -1554,6 +1554,21 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
return channel().newFailedFuture(cause); return channel().newFailedFuture(cause);
} }
@Override
public boolean isWritable() {
DefaultChannelHandlerContext ctx = prev;
for (;;) {
if (ctx.hasOutboundByteBuffer()) {
return ctx.isWritable();
}
if (ctx.hasOutboundMessageBuffer()) {
return ctx.isWritable();
}
ctx = ctx.prev;
}
}
private boolean isInboundBufferFreed() { private boolean isInboundBufferFreed() {
return pipeline.inboundBufferFreed; return pipeline.inboundBufferFreed;
} }

View File

@ -1336,4 +1336,9 @@ final class DefaultChannelPipeline implements ChannelPipeline {
public Iterator<Map.Entry<String, ChannelHandler>> iterator() { public Iterator<Map.Entry<String, ChannelHandler>> iterator() {
return toMap().entrySet().iterator(); return toMap().entrySet().iterator();
} }
@Override
public boolean isWritable() {
return tail.isWritable();
}
} }