Synchronous Mutliplexing in netty
"이희승 (Trustin Lee)"
trustin at gmail.com
Wed Jul 15 03:00:55 EDT 2009
Hi Rahul,
On 07/14/2009 02:59 PM, Rahul Patil wrote:
> Hi Trustin,
> Thanks for the prompt reply.
> To put in detail, what we are looking for is as follows:
> We have multiple NIO clients which keeps a persistent connection to a single
> NIO server.
> The server sends commands to these clients to process requests, so in this
> case it’s the client which does the work while the server is waiting for the
> response.
> We want to have all these requests from server to a particular client to be
> blocking calls, i.e. synchronous.
If you write a message from the server to the client and wait until the
message is written out, it's blocking and synchronous. You can get
notified when the write operation is completed to do so. Please refer
to ChannelFutureListener and ChannelFuture. ChannelFuture is returned
by Channel.write().
> Besides, there could be multiple simultaneous requests (different commands)
> coming from the server to the same client over the same cannel.
> Since we have single handler instance for all these requests (being single
> pipeline for a single client-server channel) my concern is about the
> blocking queue.
> As per my following code, I need to keep taking/offering to the queue this I
> find the response which interests me.
> My fear is, this will cause an unnecessary multithreading load as each time
> I call take as it will notify all the waiting threads.
> I am sorry if I am wrong in making the above assumption as I am not much
> familiar with multithreading.
I think it's not a Netty question but a general concurrency data
structure question. One solution could be having a separate queue for
each work ID if possible.
> If any calling thread dies for some reason, the object in the queue won't be
> taken out and will stay there forever.
Unnecessarily terminating thread is a bug that needs a fix.
> So essentially, we are looking for some mechanism where we can have multiple
> pipelines per channel (or multiple local channels per physical channel) so
> that we will have only one object in the queue to make that particular
> pipeline synchronous.
I'm not sure, but are you looking for SynchronousQueue?
HTH,
Trustin
More information about the netty-users
mailing list