Class DynamicAddressConnectHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.address.DynamicAddressConnectHandler
- All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
ChannelOutboundHandler implementation which allows to dynamically replace the used
remoteAddress and / or localAddress when making a connection attempt.
This can be useful to for example bind to a specific NetworkInterface based on
the remoteAddress.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidconnect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) CallsChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.protected SocketAddresslocalAddress(SocketAddress remoteAddress, SocketAddress localAddress) Returns the localSocketAddressto use forChannelOutboundInvoker.connect(SocketAddress, SocketAddress)based on the originalremoteAddressandlocalAddress.protected SocketAddressremoteAddress(SocketAddress remoteAddress, SocketAddress localAddress) Returns the remoteSocketAddressto use forChannelOutboundInvoker.connect(SocketAddress, SocketAddress)based on the originalremoteAddressandlocalAddress.Methods inherited from class ChannelOutboundHandlerAdapter
bind, close, deregister, disconnect, flush, read, writeMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
exceptionCaught, handlerAdded, handlerRemoved
-
Constructor Details
-
DynamicAddressConnectHandler
public DynamicAddressConnectHandler()
-
-
Method Details
-
connect
public final void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) Description copied from class:ChannelOutboundHandlerAdapterCallsChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
connectin interfaceChannelOutboundHandler- Overrides:
connectin classChannelOutboundHandlerAdapter- Parameters:
ctx- theChannelHandlerContextfor which the connect operation is maderemoteAddress- theSocketAddressto which it should connectlocalAddress- theSocketAddresswhich is used as source on connectpromise- theChannelPromiseto notify once the operation completes
-
localAddress
protected SocketAddress localAddress(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception Returns the localSocketAddressto use forChannelOutboundInvoker.connect(SocketAddress, SocketAddress)based on the originalremoteAddressandlocalAddress. By default, this method returns the givenlocalAddress.- Throws:
Exception
-
remoteAddress
protected SocketAddress remoteAddress(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception Returns the remoteSocketAddressto use forChannelOutboundInvoker.connect(SocketAddress, SocketAddress)based on the originalremoteAddressandlocalAddress. By default, this method returns the givenremoteAddress.- Throws:
Exception
-