Reputation: 1857
When one calls channel.connect
a future is returned. Then for each outbound-handler .connect()
is called passing a promise. (I guess they are really the same object, but let's ignore that.) So far so clear.
At some point listeners added to (a) the future, to (b) the promise are notified about completion. Also, at some point (c) .channelActive()
will be called on all inbound handlers (as far as I understood this replaces .connected from netty-3.x). And finally there is the point in time (d) when isActive()
returns true for the first time.
Question: Is there a defined order between (a) to (d)?
Context: I'm trying to implement a handler that writes a message to the channel on connection. It works mostly well, but sometimes it seems that handler is not the first one to get to write.
Upvotes: 1
Views: 301
Reputation: 23567
The order is guaranteed but it may trigger an event earlier then you are able to add the listener itself as everything is async. If you want to make sure that your ChannelFutureListener is called before channelActive() in all cases you can just create a ChannelPromise via channel.newPromise() add a ChannelListener to it and then pass the ChannelPromise to the connect method.
The contract is that the ChannelPromise will always be notified before the corresponding methods in ChannelOutboundHandler/ChannelInboundHandler
Upvotes: 1