[#1058] Add Channel/ChannelHandlerContext/ChannelPipeline.isWritable()
This commit is contained in:
parent
1c6ed9b2ce
commit
4e36fbca58
@ -133,6 +133,11 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable() {
|
||||
return pipeline.isWritable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Integer id() {
|
||||
return id;
|
||||
|
@ -108,6 +108,11 @@ public interface Channel extends AttributeMap, ChannelOutboundInvoker, ChannelPr
|
||||
*/
|
||||
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}.
|
||||
*/
|
||||
|
@ -128,6 +128,12 @@ public interface ChannelHandlerContext
|
||||
extends AttributeMap, ChannelPropertyAccess,
|
||||
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}.
|
||||
*/
|
||||
|
@ -732,6 +732,11 @@ public interface ChannelPipeline extends ChannelInboundInvoker, ChannelOutboundI
|
||||
*/
|
||||
Map<String, ChannelHandler> toMap();
|
||||
|
||||
/**
|
||||
* Return {@code true} if the outbound buffer is writable.
|
||||
*/
|
||||
boolean isWritable();
|
||||
|
||||
@Override
|
||||
ChannelPipeline fireChannelRegistered();
|
||||
|
||||
|
@ -1554,6 +1554,21 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
||||
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() {
|
||||
return pipeline.inboundBufferFreed;
|
||||
}
|
||||
|
@ -1336,4 +1336,9 @@ final class DefaultChannelPipeline implements ChannelPipeline {
|
||||
public Iterator<Map.Entry<String, ChannelHandler>> iterator() {
|
||||
return toMap().entrySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable() {
|
||||
return tail.isWritable();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user