Synchronous Mutliplexing in netty
Frederic Bregier
fredbregier at free.fr
Tue Jul 14 04:57:29 EDT 2009
Hi,
I don't know if it will answer your question, but I have to do multiplexing
on one channel using several local clients. To do this I made as the
following using LocalChannel:
Any message received into the Channel (NioChannel or networked channel) is
decoded and pass it to a LocalChannel that implements one final client using
a data structure that associate both network channel and local channel. Each
message contains a reference of the localChannel Id (and remote localChannel
Id too as it follows the exactly same way).
When the LocalChannel client wants to send something to the remote client,
it directly writes to the network channel.
So to resume, the NioChannel implements a handler that is only responsible
to handle multiplexing between several LocalChannels, while each
LocalChannel is really doing the business job.
By doing this, I have no queue to handle, but I need to add
OrderedMemoryAwareThreadPoolExecutor at both network pipeline and local
pipeline in order to be sure that messages arrive in order and that
different volatile threads will be used for each part.
The only thing that I had to take care is to handle properly the relation
between LocalChannel and the message received from the network channel. Each
message contains as header 2 integer, one for the remote LocalChannel Id (in
order to know to which remote LocalChannel the answer will be addressed) and
the local LocalChannel Id (in order to know who has the local session
object).
I don't know if this way answer to your question, specially on the
"synchronous" part...
HTH,
Frederic
Rahul Patil wrote:
>
> Hi All,
> After evaluating few NIO frameworks we settled on netty owing to its
> flexible and comprehensive architechture. Now I am struggling with a way
> to use netty for synchronous mulitiplexed calls. Following the factorial
> example I have been able to address the synchronous part using the
> following code:
> public Message getMessage(long workID)
> {
> while (true)
> {
> try
> {
> Message am = queue.take();
> if(am.getWorkID() == workID){
> return am;
> }
> else
> {
> queue.offer(am);
> }
> }
> catch (InterruptedException e)
> {
> // Ignore.
> }
> }
> }
> I cannot do a peek as the queue can contain more objects so I need to use
> take and offer.
> What essentially follows then is to make it multiplexed as we need to make
> multiple calls over the same channel to avoid the overhead of using
> blocking queue.
> I looked at some other pose in this forum and came across LocalChannel.
> However, I am not clear about the rationale behind it and not sure how it
> can be used for multiplexing.
> I ran into xsockets while searching for multiplexing and wondered why this
> feature is lacking in netty.
> Considering the benefits of netty I don't want to switch to xsocket but I
> am stuck with this issue which is hindering our project.
> Any help in this matter would be highly appreciated.
>
-----
Hardware/Software Architect
--
View this message in context: http://n2.nabble.com/Synchronous-Mutliplexing-in-netty-tp3254213p3254648.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list