Hi,<br><br>First off, welcome! :)<br><br><div class="gmail_quote">On Wed, Jan 7, 2009 at 6:34 AM, new2nw <span dir="ltr">&lt;<a href="mailto:makunag@hotmail.com">makunag@hotmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The code is based totally on factorial example. And here are my dumb<br>
questions:<br>
<br>
How do I handle netty client?<br>
<br>
1. For each request(thread) out of my process do I need to create a new<br>
channel (I mean create a new connection) as in the example above? Or shall I<br>
be using the same channel by not closing it and continue to write on it?</blockquote><div><br>You can keep the channel open and keep sending requests.&nbsp; Of course, you can open and close a connection for each request, too.<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2. If I create a new connection for each request; is there a performance<br>
issue?</blockquote><div><br>Yes.&nbsp; You will see a lot of TIME_WAIT state if you type &#39;netstat -an&#39; in your console.&nbsp; If the number of TIME_WAIT state fills up, the channel will not be opened as fast as before until TIME_WAIT states are cleared.&nbsp; I&#39;d recommend you to keep the connection open and reconnect only when it&#39;s disconnected for some reason.<br>
&nbsp;<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">3. If I create a new connection for each request; shall I use same channel<br>
factory ?</blockquote><div><br>Yes.&nbsp; I&#39;d actually use only one channel factory to create all channels.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
4. If I can reuse same connection, how do I match request with response? Do<br>
I have to have my own logic?</blockquote><div><br>There are two ways to achieve this.&nbsp; The first approach is to assume that the responses are always responded in order.&nbsp; Then you can safely assume that the first response is always correlates to the first request and so forth.&nbsp; The second approach is to add some sequence ID for each request and convey the same sequence ID for the corresponding response.&nbsp; The second approach is more flexible but you might be just fine with the first one.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">5. In the above example using blocking queue and &quot;one&quot; as channel pipelien<br>

coverage, am I guranteed to receive the response corresponding to my<br>
request, or I have to look at the response and decide if its the right<br>
response?</blockquote><div><br>ChannelPipelineCoverage is solely for documentation purpose.&nbsp; It just depends on how many handler instances you create to handler events.&nbsp; If you added the same handler instance for more than one ChannelPipeline, then you will receive all responses from all channels in one handler instance.&nbsp; If you added a new handler for each Channel, then each handler instance will receive the response which is related with the Channel it belongs to.&nbsp; <br>
&nbsp;<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">6. Is this an asynchronus process? I am confused as each request is waiting<br>
for response (synch) but at the same time each requests doesn&#39;t have to wait<br>
for the other to finish as netty server will keep receiving requests from<br>
each channels.</blockquote><div><br>Everything is asynchronous.&nbsp; The Factorial client is synchronous because it explicitly waits for a response using a blocking queue.<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
7. Am I missing something important in the above example code.</blockquote><div><br>I think you understood pretty well about Netty.&nbsp; :)<br><br>You might want to add an ExecutionHandler to the pipeline though.&nbsp; Please take a look at the Javadoc of the classes in org.jboss.netty.handler.execution.<br>
</div></div><br>HTH,<br><br>— Trustin Lee, <a href="http://gleamynode.net/">http://gleamynode.net/</a>