[erlang-questions] Is it possible to add an filter property for the erlang process?

Chris Hicks silent_vendetta@REDACTED
Thu Jun 17 08:12:23 CEST 2010


Can't you just do this with an _Other clause in your receive statement? So something along the lines of:
receive{foo, Message} ->dosomethingfancyhere,loop();
_Other ->loop()end.

> Date: Thu, 17 Jun 2010 12:29:16 +0800
> From: litaocheng@REDACTED
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] Is it possible to add an filter property for the erlang process?
> 
> hi, buddies.
> my question is if it's possible to add an "filter" property for the erlang
> process, so that process can drop the uninterested messages. then we can
> reduce the needless memory consuming.
> 
> like this:
> % spawn a process with filter : {foo, _}
> PidA = spawn(?MODULE, do_something, [], [{filter, {foo, _}}]),
> 
> % the message {foo, hello} will be saved to PidA message queue, because it
> match the filter
> PidA ! {foo, hello},
> 
> % this message will be dropped
> PidA ! {bar, world},
> 
> % reset the filter
> process_flag(filter, [_|_]),
> 
> % this message will be stored in message queue
> PidA ! "hello world",
> ok.
> 
> by this feature,  I can write the code like this ( in my logging library,
> which is similar with python logging module):
> {ok, _} = logging:start_logger("logname"),
> Logger = logging:get_logger("logname"),
> Logger:set_level(?CRITICAL),
> Logger:debug("log"),
> Logger:warning("log"),
> Logger:critical("log"),
> ok
> 
> logger is an parameterized module, logging is an gen_server process, in
> logging module:
> handle_call({set_level, Level}, _From, State) ->
>     process_flag(filter, #log_record{level = MsgLevel} when MsgLevel >
> Level),
>     {reply, ok, State};
> 
> in my logging library,  I have two methods to resolve this problem:
> * dynamic compile the logger module, in the debug, info, warning, error
> function check if the log allowed
> * in logging gen_server process handl_xxx function, test if the log record
> is allowed
> all two solutions have flew.
> 
> I want to known if this process filter feature is valuable?
> thanks

 		 	   		  
_________________________________________________________________
Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1


More information about the erlang-questions mailing list