public abstract static class ProtocolNegotiators.AbstractBufferingHandler extends ChannelDuplexHandler
writeBufferedAndRemove(ChannelHandlerContext)
or
fail(ChannelHandlerContext, Throwable)
is called. This handler allows us to
write to a Channel
before we are allowed to write to it officially
i.e. before it's active or the TLS Handshake is complete.ChannelHandler.Sharable
Modifier | Constructor and Description |
---|---|
protected |
AbstractBufferingHandler(ChannelHandler... handlers) |
Modifier and Type | Method and Description |
---|---|
void |
channelInactive(ChannelHandlerContext ctx)
If this channel becomes inactive, then notify all buffered writes that we failed.
|
void |
channelRegistered(ChannelHandlerContext ctx)
When this channel is registered, we will add all the ChannelHandlers passed into our
constructor to the pipeline.
|
void |
close(ChannelHandlerContext ctx,
ChannelPromise future)
If we are still performing protocol negotiation, then this will propagate failures to all
buffered writes.
|
void |
connect(ChannelHandlerContext ctx,
SocketAddress remoteAddress,
SocketAddress localAddress,
ChannelPromise promise)
Do not rely on channel handlers to propagate exceptions to us.
|
void |
exceptionCaught(ChannelHandlerContext ctx,
Throwable cause)
If we encounter an exception, then notify all buffered writes that we failed.
|
protected void |
fail(ChannelHandlerContext ctx,
Throwable cause)
Propagate failures to all buffered writes.
|
void |
flush(ChannelHandlerContext ctx)
Calls to this method will not trigger an immediate flush.
|
void |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Buffers the write until either
writeBufferedAndRemove(ChannelHandlerContext) is
called, or we have somehow failed. |
protected void |
writeBufferedAndRemove(ChannelHandlerContext ctx) |
bind, deregister, disconnect, read
channelActive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded, handlerRemoved
protected AbstractBufferingHandler(ChannelHandler... handlers)
handlers
- the ChannelHandlers are added to the pipeline on channelRegistered and
before this handler.public void channelRegistered(ChannelHandlerContext ctx) throws Exception
channelRegistered
in interface ChannelInboundHandler
channelRegistered
in class ChannelInboundHandlerAdapter
Exception
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception
NettyClientHandler
is an example of a class that does not propagate exceptions.
Add a listener to the connect future directly and do appropriate error handling.connect
in interface ChannelOutboundHandler
connect
in class ChannelDuplexHandler
Exception
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
exceptionCaught
in interface ChannelHandler
exceptionCaught
in interface ChannelInboundHandler
exceptionCaught
in class ChannelInboundHandlerAdapter
Exception
public void channelInactive(ChannelHandlerContext ctx) throws Exception
channelInactive
in interface ChannelInboundHandler
channelInactive
in class ChannelInboundHandlerAdapter
Exception
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
writeBufferedAndRemove(ChannelHandlerContext)
is
called, or we have somehow failed. If we have already failed in the past, then the write
will fail immediately.write
in interface ChannelOutboundHandler
write
in class ChannelDuplexHandler
Exception
public void flush(ChannelHandlerContext ctx)
writeBufferedAndRemove(ChannelHandlerContext)
.flush
in interface ChannelOutboundHandler
flush
in class ChannelDuplexHandler
public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Exception
close
in interface ChannelOutboundHandler
close
in class ChannelDuplexHandler
Exception
protected final void fail(ChannelHandlerContext ctx, Throwable cause)
protected final void writeBufferedAndRemove(ChannelHandlerContext ctx)