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 oneChannelHandler
with the outbound handling of anotherChannelHandler
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CombinedChannelDuplexHandler()
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.void
channelActive(ChannelHandlerContext ctx)
TheChannel
of theChannelHandlerContext
is now activevoid
channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)
Gets called if aThrowable
was thrown when handling inbound events.void
channelInactive(ChannelHandlerContext ctx)
TheChannel
of theChannelHandlerContext
was registered is now inactive and reached its end of lifetime.void
channelInboundEvent(ChannelHandlerContext ctx, Object evt)
Gets called if a custom inbound event happened.void
channelRead(ChannelHandlerContext ctx, Object msg)
Invoked when the currentChannel
has read a message from the peer.void
channelReadComplete(ChannelHandlerContext ctx)
Invoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object)
.void
channelRegistered(ChannelHandlerContext ctx)
void
channelShutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)
TheChannel
of theChannelHandlerContext
was shutdown in one direction.void
channelUnregistered(ChannelHandlerContext ctx)
void
channelWritabilityChanged(ChannelHandlerContext ctx)
Gets called once the writable state of aChannel
changed.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.void
flush(ChannelHandlerContext ctx)
Called once a flush operation is made.void
handlerAdded(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was added to the actual context and it's ready to handle events.void
handlerRemoved(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.protected I
inboundHandler()
protected void
init(I inboundHandler, O outboundHandler)
Initialized this handler with the specified handlers.boolean
isSharable()
Returnstrue
if this handler is sharable and thus can be added to more than oneChannelPipeline
.protected O
outboundHandler()
long
pendingOutboundBytes(ChannelHandlerContext ctx)
The number of the outbound bytes that are buffered / queued in thisChannelHandler
.void
read(ChannelHandlerContext ctx)
InterceptsChannelHandlerContext.read()
.Future<Void>
register(ChannelHandlerContext ctx)
Called once a register operation is made to register for IO on theEventLoop
.void
removeInboundHandler()
Removes the inboundChannelHandler
that was combined in thisCombinedChannelDuplexHandler
.void
removeOutboundHandler()
Removes the outboundChannelHandler
that 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:ChannelHandler
Returnstrue
if 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 inboundChannelHandler
that was combined in thisCombinedChannelDuplexHandler
.
-
removeOutboundHandler
public final void removeOutboundHandler()
Removes the outboundChannelHandler
that was combined in thisCombinedChannelDuplexHandler
.
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called after theChannelHandler
was 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:ChannelHandler
Gets called after theChannelHandler
was 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:ChannelHandler
TheChannel
of theChannelHandlerContext
is now active- Throws:
Exception
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
TheChannel
of theChannelHandlerContext
was 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:ChannelHandler
TheChannel
of theChannelHandlerContext
was 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
- theChannelHandlerContext
for which we notify about the completed shutdown.direction
- theChannelShutdownDirection
of the completed shutdown.- Throws:
Exception
-
channelExceptionCaught
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
Description copied from interface:ChannelHandler
Gets called if aThrowable
was thrown when handling inbound events.- Throws:
Exception
-
channelInboundEvent
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception
Description copied from interface:ChannelHandler
Gets called if a custom inbound event happened.- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandler
Invoked when the currentChannel
has read a message from the peer.- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Invoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object)
. IfChannelOption.AUTO_READ
is off, no further attempt to read an inbound data from the currentChannel
will be made untilChannelHandlerContext.read()
is called.- Throws:
Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called once the writable state of aChannel
changed. You can check the state withChannel.writableBytes()
orChannel.isWritable()
.- Throws:
Exception
-
bind
public Future<Void> bind(ChannelHandlerContext ctx, SocketAddress localAddress)
Description copied from interface:ChannelHandler
Called once a bind operation is made.- Parameters:
ctx
- theChannelHandlerContext
for which the bind operation is madelocalAddress
- theSocketAddress
to which it should bound- Returns:
- the
Future
which will be notified once the operation completes.
-
connect
public Future<Void> connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress)
Description copied from interface:ChannelHandler
Called once a connect operation is made.- Parameters:
ctx
- theChannelHandlerContext
for which the connect operation is maderemoteAddress
- theSocketAddress
to which it should connectlocalAddress
- theSocketAddress
which is used as source on connect- Returns:
- the
Future
which will be notified once the operation completes.
-
disconnect
public Future<Void> disconnect(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandler
Called once a disconnect operation is made.- Parameters:
ctx
- theChannelHandlerContext
for which the disconnect operation is made- Returns:
- the
Future
which will be notified once the operation completes.
-
close
public Future<Void> close(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandler
Called once a close operation is made.- Parameters:
ctx
- theChannelHandlerContext
for which the close operation is made- Returns:
- the
Future
which will be notified once the operation completes.
-
shutdown
public Future<Void> shutdown(ChannelHandlerContext ctx, ChannelShutdownDirection direction)
Description copied from interface:ChannelHandler
Called once a shutdown operation was requested and should be executed.- Parameters:
ctx
- theChannelHandlerContext
for which the shutdown operation is madedirection
- theChannelShutdownDirection
that is used.- Returns:
- the
Future
which will be notified once the operation completes.
-
register
public Future<Void> register(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandler
Called once a register operation is made to register for IO on theEventLoop
.- Parameters:
ctx
- theChannelHandlerContext
for which the register operation is made- Returns:
- the
Future
which will be notified once the operation completes.
-
deregister
public Future<Void> deregister(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandler
Called once a deregister operation is made from the current registeredEventLoop
.- Parameters:
ctx
- theChannelHandlerContext
for which the deregister operation is made- Returns:
- the
Future
which will be notified once the operation completes.
-
read
public void read(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandler
InterceptsChannelHandlerContext.read()
.
-
write
public Future<Void> write(ChannelHandlerContext ctx, Object msg)
Description copied from interface:ChannelHandler
Called once a write operation is made. The write operation will write the messages through theChannelPipeline
. Those are then ready to be flushed to the actualChannel
onceChannel.flush()
is called.- Parameters:
ctx
- theChannelHandlerContext
for which the write operation is mademsg
- the message to write- Returns:
- the
Future
which will be notified once the operation completes.
-
flush
public void flush(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandler
Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.- Parameters:
ctx
- theChannelHandlerContext
for which the flush operation is made
-
sendOutboundEvent
public Future<Void> sendOutboundEvent(ChannelHandlerContext ctx, Object event)
Description copied from interface:ChannelHandler
Called once a custom defined outbound event was sent. This operation will pass the event through theChannelPipeline
in the outbound direction.- Parameters:
ctx
- theChannelHandlerContext
for which the operation is made.event
- the event.- Returns:
- the
Future
which will be notified once the operation completes.
-
pendingOutboundBytes
public long pendingOutboundBytes(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandler
The number of the outbound bytes that are buffered / queued in thisChannelHandler
. This number will affect the writability of theChannel
together the buffered / queued bytes in theChannel
itself. By default this methods returns0
. If theChannelHandler
implementation buffers / queues outbound data this methods should be implemented to return the correct value.- Parameters:
ctx
- theChannelHandlerContext
for which the operation is made.- Returns:
- the number of buffered / queued bytes.
-
-