Reconnecting a client automatically *without losing state*
tsuna
tsunanet at gmail.com
Mon Aug 2 17:39:48 EDT 2010
On Mon, Aug 2, 2010 at 7:05 AM, brunodecarvalho <kindernade at gmail.com> wrote:
> Now your listener can attempt to reconnect the exact same handler by either
> creating a new pipeline with the same handler in place or access the
> pipeline of the handler that just disconnected and create a new bootstrap
> with it, thus reusing the same handler (which will be using a different
> Channel in each connection).
Ah, I didn't think about creating a new ClientBootstrap and calling
setPipeline on it, instead of setPipelineFactory, in order to re-use
the same pipeline (and thus re-use the existing stateful handlers).
The only problem remaining is that unfortunately if I get a
ConnectException during the initial connection, then this.channel will
never be set, so I don't know where to reconnect to. In your example
you store the host and port in the handler as they're given to you
through the constructor, but it's not clear how this information would
reach the constructor in the first place. When you create a
ClientBootstrap for the very first time, you give it a shared
ChannelPipelineFactory that is re-used to create any number of new
clients, and because this ChannelPipelineFactory is shared, it doesn't
have access to the host / port for this particular client, so it
cannot give it to the constructor of your handler.
--
Benoit "tsuna" Sigoure
Software Engineer @ www.StumbleUpon.com
More information about the netty-users
mailing list