Erlang/OTP Forums

Author Message

<  Open Telecom Platform (OTP)  ~  how do I implement priority message in gen_server ?

garyng
Posted: Sat Aug 18, 2007 4:28 am Reply with quote
Joined: 15 Aug 2007 Posts: 7
Hi,

Suppose I have 2 processes which shares the same socket(tcp_reader/tcp_writer) where the tcp_reader read the request from the socket then gen_server:cast() to tcp_writer to let it handle the sending.

So it is possible that tcp_writer may have a number of requests in the queue. Now if the reader process get a "shutdown" from the client, it would send a message to the writer and let it stop as well(to get in front of all the queued send request), after it has finished the one on hand.

If I implement the receive loop, I can use the timeout == 0 tricks but not sure how it should be done in gen_server.
View user's profile Send private message
francesco
Posted: Mon Aug 20, 2007 7:20 am Reply with quote
User Joined: 07 Jul 2006 Posts: 249 Location: London
Unfortunately, OTP behaviors (Including gen_servers and FSMs) lack selective receives (And thereof priorities). The only way to solve the selective receive problem in a clean way is to implement your own behavior. (See Ulf Wiger's presentation at the EUC two years ago, http://www.erlang.se/euc/05/1500Wiger.ppt ) or search on selective receive in the search field on the bottom left.

To solve your problem, however, I would look into using exit signals and links, as that is the way it is usually solved.

If you want dirty workarounds for selective receives in gen_servers, let me know. It will however have to be after lunch, as I will loose my appetite Smile

Francesco
--
http://www.erlang-consulting.com
View user's profile Send private message Visit poster's website
Jan Henry Nystrom
Posted: Mon Aug 20, 2007 8:13 am Reply with quote
User Joined: 09 Oct 2006 Posts: 28 Location: Uppsala, Sweden
garyng wrote:
Hi,

[Snip]

If I implement the receive loop, I can use the timeout == 0 tricks but not sure how it should be done in gen_server.


Hi,

I hope you forgive the self promotion nature of this, but I have a generic server version that does the selective receive (fiendishly expensive which is was puts Francesco off his food). It will be presented at the Erlang Workshop in October with a discussion on general issues concerning selective receive. I will release the code on trap exit as soon as I have the time to write the proper documentation.

/Cheers Henry

_________________
Jan Henry Nystrom
Training & Research Manager @ Erlang Training and Consulting Ltd
http://www.erlang-consulting.com
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger ICQ Number
garyng
Posted: Mon Aug 20, 2007 10:07 am Reply with quote
Joined: 15 Aug 2007 Posts: 7
francesco wrote:

To solve your problem, however, I would look into using exit signals and links, as that is the way it is usually solved.


Can I have a pointer on how to do it that way ?
View user's profile Send private message
number
Posted: Mon Jun 04, 2012 8:38 am Reply with quote
User Joined: 04 Jun 2012 Posts: 18
I read your sharing, I feel really good.I was a football enthusiast.I hope you like my share. Football is a very exciting sport. Each play football am very excited.
Soccer Jerseys
Germany Football Shirt
England Football Shirt
Barcelona Jersey
Netherlands Jersey
Spain Soccer Jersey
View user's profile Send private message AIM Address

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum