New to netty

manish_iitg excellencetechnologies08 at gmail.com
Thu Dec 11 21:10:46 EST 2008


Hello,

This was exactly what i was looking for. I will surely try this out. Also do
i need to add an execution handler in my pipleline when using such a queue.
I am not able to understand the purpose of execution handler, both order
aware and thread pool aware. Could you please explain that also.

Thanks


Frederic Bregier wrote:
> 
> Hi Manish,
> 
> It seems you want to synchronize the client with the reception of
> the answer of the server, right ?
> As the reception is asynchronous, you have to implement in another way
> than relying on Netty for that. Let me explain what I do for that.
> 
> You have to implement your logic both in the client (outside Netty)
> and in the SimpleChannelHandler (so using Netty where you handle
> connection, send
> and receive).
> I would suggest you to implement something similar as follow:
> - Add to your business logic a blockingQueue or similar.
> - When you create your client, create this blockingQueue too (like 
>   ConcurrentLinkedQueue).
> - The client initialize all necessary stuff for the connection to be made.
> - When the client hasked the connection, just wait for the connection to
> be done.
> - Then still in the client just wait on this blockingQueue to have a
> response.
> - In the "channelConnected" method of your SimpleChannelHandler of your
> client,
>   the client part sends its message to the server.
> - In the "messageReceived" method of your SimpleChannelHandler of your
> client,
>   when the client part receives the answer from the server, just put it
> into
>   the blocking queue.
> - It will release the wait on the blockingQueue on the client side, such
> that
>   you have your "business" synchronisation.
> 
> A little graphic view if not clear (I feel like I am not so clear ;-)
> 
> Client.class
>  - BlockingQueue<msg>
>  - Create a ClientBootStrap to connect to the server
>  - Create your own SimpleChannelHandler giving it your BlockingQueue and
> the message
>    you want to send to the server
>  - Connect to the server using the ClientBootStrap
>  - wait on msg = BlockingQueue.take()
>              => YouSimpleChannelHandler.class
>                  - channelConnected => send the message to the server
>                  - messageReceived => add the message receive from the
> server into the
>                    BlockingQueue (if session is no more useful, close it
> now)
>              <=
>  - end of wait on take()
>  - now you can continue (close the session if you want, or whatever you
> have to)
> 
> Hope this helps,
> Frederic
> 

-- 
View this message in context: http://n2.nabble.com/New-to-netty-tp1625621p1646221.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list