Async Client with Callbacks

Jeff G. jeff at steelhouse.com
Tue Jul 5 12:13:44 EDT 2011


One way you can do this is to put all the state into a ChannelLocal (e.g., if
you have some instance of some class in a one-to-one association with
requests, you might put it in a ChannelLocal).  Since the response from the
server gets associated with the same netty Channel that your request was
associated with, your upstream handler can fetch the state from the
ChannelLocal and do stuff with it.  For example, if you have a class with a
one-to-one correspondence with requests, that class could have a callback
method in it.  Your upstream handler would fetch the instance from the
ChannelLocal and call the callback with whatever data from the response
message that you want to use.  The hardest part of using ChannelLocal, for
me, was trusting that the framework is doing the right thing and associating
the right response with the right request (which it does).  This way you
wouldn't be waiting on a future, though; you could have some state flag or
something that the callback sets instead so the client knows it can move to
the next state or whatever.  I've done this with my own clients at a couple
of companies and it's worked out very well, though if you don't have any
class where you've got a one-to-one correspondence with requests, you'll
have to work out what to put in the ChannelLocal that makes sense in your
application.

You might also try using attachments, though I haven't used those at all and
can't comment on how they work (but I've used ChannelLocal a lot).

--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Async-Client-with-Callbacks-tp6507468p6550448.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list