New to Netty - Basic simple questions

new2nw makunag at hotmail.com
Tue Jan 6 16:34:57 EST 2009


I am new to netty, new to N/W programming. So forgive me if I am asking
fairly simple and dumb questions. 

I have a multi threaded process (kind of server) which receives multiple
requests at a time, I do some processing with each request and then my
requirement is to pass the request to a remote process (using netty) and get
the response back corresponding to each request. All should happen in
asynchronus fashion, but at the same time all response should match the
corresponding request.

Using factorial example, I have created a netty server which will bind and
accept incoming connection. I created a server handler which will on
messageReceived() read the message, do some business logic and write back
the corresponding response to channel. The channel pipeline coverage for
this handler is "all". I have also created server pipeline factory which
will add encoder, decoder and my server handler to pipeline. I start(bind)
my netty server and keep it running(listening). 

On client side, I have created a netty client which connects to the netty
server, await and get a channel back. Then I write to the channel, await and
get client handler back. Using client handler's getResponse() method I get
my response back and pass it to my process. I created a client handler which
has a blocking queue as instance variable. on messagereceived() I write to
blocking queue after closing the channel. On getResponse() method; I take
the message from blocking queue and return. The channel pipeline coverage
for this handler is "one". I have also created client pipeline factory which
will add encoder, decoder and my client handler to pipeline.

The code is based totally on factorial example. And here are my dumb
questions: 

 How do I handle netty client? 

1. For each request(thread) out of my process do I need to create a new
channel (I mean create a new connection) as in the example above? Or shall I
be using the same channel by not closing it and continue to write on it?

2. If I create a new connection for each request; is there a performance
issue?

3. If I create a new connection for each request; shall I use same channel
factory ?

4. If I can reuse same connection, how do I match request with response? Do
I have to have my own logic? 

5. In the above example using blocking queue and "one" as channel pipelien
coverage, am I guranteed to receive the response corresponding to my
request, or I have to look at the response and decide if its the right
response?

6. Is this an asynchronus process? I am confused as each request is waiting
for response (synch) but at the same time each requests doesn't have to wait
for the other to finish as netty server will keep receiving requests from
each channels.

7. Am I missing something important in the above example code.

Many thanks is advance !
-- 
View this message in context: http://n2.nabble.com/New-to-Netty---Basic-simple-questions-tp2119529p2119529.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list