Module io.netty5.transport
Package io.netty5.channel
Class CombinedChannelDuplexHandler<I extends ChannelHandler,O extends ChannelHandler>
- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.channel.CombinedChannelDuplexHandler<I,O>
-
- All Implemented Interfaces:
ChannelHandler
- Direct Known Subclasses:
HttpClientCodec,HttpServerCodec
public class CombinedChannelDuplexHandler<I extends ChannelHandler,O extends ChannelHandler> extends ChannelHandlerAdapter
Combines the inbound handling of oneChannelHandlerwith the outbound handling of anotherChannelHandler.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCombinedChannelDuplexHandler()Creates a new uninitialized instance.CombinedChannelDuplexHandler(I inboundHandler, O outboundHandler)Creates a new instance that combines the specified two handlers into one.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Future<Void>bind(ChannelHandlerContext ctx, SocketAddress localAddress)Called once a bind operation is made.voidchannelActive(ChannelHandlerContext ctx)TheChannelof theChannelHandlerContextis now activevoidchannelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)Gets called if aThrowablewas thrown when handling inbound events.voidchannelInactive(ChannelHandlerContext ctx)TheChannelof theChannelHandlerContextwas registered is now inactive and reached its end of lifetime.voidchannelInboundEvent(ChannelHandlerContext ctx, Object evt)Gets called if a custom inbound event happened.voidchannelRead(ChannelHandlerContext ctx, Object msg)Invoked when the currentChannelhas read a message from the peer.voidchannelReadComplete(ChannelHandlerContext ctx)Invoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object).voidchannelRegistered(ChannelHandlerContext ctx)voidchannelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)TheChannelof theChannelHandlerContextwas shutdown in one direction.voidchannelUnregistered(ChannelHandlerContext ctx)voidchannelWritabilityChanged(ChannelHandlerContext ctx)Gets called once the writable state of aChannelchanged.Future<Void>close(ChannelHandlerContext ctx)Called once a close operation is made.Future<Void>connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress)Called once a connect operation is made.Future<Void>deregister(ChannelHandlerContext ctx)Called once a deregister operation is made from the current registeredEventLoop.Future<Void>disconnect(ChannelHandlerContext ctx)Called once a disconnect operation is made.voidflush(ChannelHandlerContext ctx)Called once a flush operation is made.voidhandlerAdded(ChannelHandlerContext ctx)Gets called after theChannelHandlerwas added to the actual context and it's ready to handle events.voidhandlerRemoved(ChannelHandlerContext ctx)Gets called after theChannelHandlerwas removed from the actual context and it doesn't handle events anymore.protected IinboundHandler()protected voidinit(I inboundHandler, O outboundHandler)Initialized this handler with the specified handlers.booleanisSharable()Returnstrueif this handler is sharable and thus can be added to more than oneChannelPipeline.protected OoutboundHandler()longpendingOutboundBytes(ChannelHandlerContext ctx)The number of the outbound bytes that are buffered / queued in thisChannelHandler.voidread(ChannelHandlerContext ctx)InterceptsChannelHandlerContext.read().Future<Void>register(ChannelHandlerContext ctx)Called once a register operation is made to register for IO on theEventLoop.voidremoveInboundHandler()Removes the inboundChannelHandlerthat was combined in thisCombinedChannelDuplexHandler.voidremoveOutboundHandler()Removes the outboundChannelHandlerthat was combined in thisCombinedChannelDuplexHandler.Future<Void>sendOutboundEvent(ChannelHandlerContext ctx, Object event)Called once a custom defined outbound event was sent.Future<Void>shutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)Called once a shutdown operation was requested and should be executed.Future<Void>write(ChannelHandlerContext ctx, Object msg)Called once a write operation is made.
-
-
-
Constructor Detail
-
CombinedChannelDuplexHandler
protected CombinedChannelDuplexHandler()
Creates a new uninitialized instance. A class that extends this handler must invokeinit(ChannelHandler, ChannelHandler)before adding this handler into aChannelPipeline.
-
-
Method Detail
-
isSharable
public final boolean isSharable()
Description copied from interface:ChannelHandlerReturnstrueif this handler is sharable and thus can be added to more than oneChannelPipeline. By default, this method returnsfalse. If this method returnsfalse, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.
-
init
protected final void init(I inboundHandler, O outboundHandler)
Initialized this handler with the specified handlers.- Throws:
IllegalStateException- if this handler was not constructed via the default constructor or if this handler does not implement all required handler interfacesIllegalArgumentException- if the specified handlers cannot be combined into one due to a conflict in the type hierarchy
-
inboundHandler
protected final I inboundHandler()
-
outboundHandler
protected final O outboundHandler()
-
removeInboundHandler
public final void removeInboundHandler()
Removes the inboundChannelHandlerthat was combined in thisCombinedChannelDuplexHandler.
-
removeOutboundHandler
public final void removeOutboundHandler()
Removes the outboundChannelHandlerthat was combined in thisCombinedChannelDuplexHandler.
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called after theChannelHandlerwas added to the actual context and it's ready to handle events.- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called after theChannelHandlerwas removed from the actual context and it doesn't handle events anymore.- Throws:
Exception
-
channelRegistered
public void channelRegistered(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler- Throws:
Exception
-
channelUnregistered
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler- Throws:
Exception
-
channelActive
public void channelActive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextis now active- Throws:
Exception
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextwas registered is now inactive and reached its end of lifetime.- Throws:
Exception
-
channelShutdown
public void channelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction) throws Exception
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextwas shutdown in one direction. This might either be because the remote peer did cause a shutdown of one direction or the shutdown was requested explicit by us and was executed.- Parameters:
ctx- theChannelHandlerContextfor which we notify about the completed shutdown.direction- theChannelShutdownDirectionof the completed shutdown.- Throws:
Exception
-
channelExceptionCaught
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
Description copied from interface:ChannelHandlerGets called if aThrowablewas thrown when handling inbound events.- Throws:
Exception
-
channelInboundEvent
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception
Description copied from interface:ChannelHandlerGets called if a custom inbound event happened.- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandlerInvoked when the currentChannelhas read a message from the peer.- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerInvoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object). IfChannelOption.AUTO_READis off, no further attempt to read an inbound data from the currentChannelwill be made untilChannelHandlerContext.read()is called.- Throws:
Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called once the writable state of aChannelchanged. You can check the state withChannel.writableBytes()orChannel.isWritable().- Throws:
Exception
-
bind
public Future<Void> bind(ChannelHandlerContext ctx, SocketAddress localAddress)
Description copied from interface:ChannelHandlerCalled once a bind operation is made.- Parameters:
ctx- theChannelHandlerContextfor which the bind operation is madelocalAddress- theSocketAddressto which it should bound- Returns:
- the
Futurewhich will be notified once the operation completes.
-
connect
public Future<Void> connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress)
Description copied from interface:ChannelHandlerCalled once a connect operation is made.- Parameters:
ctx- theChannelHandlerContextfor which the connect operation is maderemoteAddress- theSocketAddressto which it should connectlocalAddress- theSocketAddresswhich is used as source on connect- Returns:
- the
Futurewhich will be notified once the operation completes.
-
disconnect
public Future<Void> disconnect(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a disconnect operation is made.- Parameters:
ctx- theChannelHandlerContextfor which the disconnect operation is made- Returns:
- the
Futurewhich will be notified once the operation completes.
-
close
public Future<Void> close(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a close operation is made.- Parameters:
ctx- theChannelHandlerContextfor which the close operation is made- Returns:
- the
Futurewhich will be notified once the operation completes.
-
shutdown
public Future<Void> shutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)
Description copied from interface:ChannelHandlerCalled once a shutdown operation was requested and should be executed.- Parameters:
ctx- theChannelHandlerContextfor which the shutdown operation is madedirection- theChannelShutdownDirectionthat is used.- Returns:
- the
Futurewhich will be notified once the operation completes.
-
register
public Future<Void> register(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a register operation is made to register for IO on theEventLoop.- Parameters:
ctx- theChannelHandlerContextfor which the register operation is made- Returns:
- the
Futurewhich will be notified once the operation completes.
-
deregister
public Future<Void> deregister(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a deregister operation is made from the current registeredEventLoop.- Parameters:
ctx- theChannelHandlerContextfor which the deregister operation is made- Returns:
- the
Futurewhich will be notified once the operation completes.
-
read
public void read(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerInterceptsChannelHandlerContext.read().
-
write
public Future<Void> write(ChannelHandlerContext ctx, Object msg)
Description copied from interface:ChannelHandlerCalled once a write operation is made. The write operation will write the messages through theChannelPipeline. Those are then ready to be flushed to the actualChannelonceChannel.flush()is called.- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to write- Returns:
- the
Futurewhich will be notified once the operation completes.
-
flush
public void flush(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.- Parameters:
ctx- theChannelHandlerContextfor which the flush operation is made
-
sendOutboundEvent
public Future<Void> sendOutboundEvent(ChannelHandlerContext ctx, Object event)
Description copied from interface:ChannelHandlerCalled once a custom defined outbound event was sent. This operation will pass the event through theChannelPipelinein the outbound direction.- Parameters:
ctx- theChannelHandlerContextfor which the operation is made.event- the event.- Returns:
- the
Futurewhich will be notified once the operation completes.
-
pendingOutboundBytes
public long pendingOutboundBytes(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerThe number of the outbound bytes that are buffered / queued in thisChannelHandler. This number will affect the writability of theChanneltogether the buffered / queued bytes in theChannelitself. By default this methods returns0. If theChannelHandlerimplementation buffers / queues outbound data this methods should be implemented to return the correct value.- Parameters:
ctx- theChannelHandlerContextfor which the operation is made.- Returns:
- the number of buffered / queued bytes.
-
-