[erlang-questions] Writers Readers problem

Garrett Smith g@REDACTED
Tue Jan 31 16:12:29 CET 2012


On Tue, Jan 31, 2012 at 5:18 AM, Roberto Majadas Lopez
<roberto.majadas@REDACTED> wrote:
> 2012/1/30 Dmitry Kolesnikov <dmkolesnikov@REDACTED>
>
> The problem is that i've n process representing an user session, and the
> token is like a "ticket" to authorize to take some information from the
> server. The real user gets the token and goes to an http server (inside the
> erlang app) a create one of the (m)-process. This process needs to check if
> the token is valid or not. If is valid, the user can get the data and the
> token is removed.

This sounds like a registered process (e.g. gen_server) that manages
the token. It's user facing API might look like this:

acquire_token() -> {ok, Token} | timeout
acquire_token(Timeout) -> {ok, Token} | timeout
release_token(Token)
is_token_valid(Token) -> boolean()

The user processes would acquire a token and pass it to an agent,
which would then validate it before proceeding. The agent could
release the token when it was done with it.

This scheme could be used for rate limiting, simple authorization, etc.

This problem seems independent of persistence, independent of crash
recovery. If you needed to recover token state from a crash, the
process would need to save off its state somewhere (I typically use a
single dets table per process) and look for that state on init.

Garrett



More information about the erlang-questions mailing list