Module ce_goat

Subsystem for goats.

Description

Subsystem for goats.

A goat represents a middleground between a (dynamic) server and a (static) data structure. Code that accesses a goat doesn't need to know or care whether the goat is dynamic or static, and indeed any given goat may switch from one state to the other throughout its lifetime.

The intent of this module is to allow for an (experimental) coding style which can be described as "Everything is a process, except what isn't, except everything is treated the same regardless of that."

This approach has also been described (unflatteringly) as "bastard semi-threaded / semi-not-threaded" programming. If it's not your cup of tea, don't use it: the Erlang runtime system is quite adequate for models along the lines of "everything is always really a process."

goats have a gen_serverish feel. They can be sent (synchronous) calls and (asynchronous) casts. When a goat is active, it will be assigned a process which will react to these requests. When it is not active, it will react to calls, but it will become active before reacting to any casts. Upon creation, a timeout value can be given. It will automatically deactivate itself after that timeout.

The goat, and everything that accesses it, is otherwise oblivious to whether it is active or not.

For this reason, goats should not identify themselves with a pid obtained from self(), but should instead use the GoatId that will be passed to their callback functions. The use of functions such as link/1 should similarly be avoided.

See also Ulf Wiger's mdisp package.

The name goat was chosen because goats are cute and have square pupils.

Function Index

behaviour_info/1Defines the callback interface.
call/2Executes a synchronous call to a goat.
cast/2Executes an asynchronous cast to a goat.
delete/1Removes a goat from existence.
goat_handler/2Handles the dynamic aspect of a goat, as required.
new/2Equivalent to new(module(), state(), infinity).
new/3Creates a new goat with the given handler module.
start/0Starts the goat subsystem.
stop/0Stops the goat subsystem.

Function Details

behaviour_info/1

behaviour_info(X1::callbacks) -> [{function(), arity()}]

Defines the callback interface.

call/2

call(GoatId::goat_id(), Message::term()) -> {ok, Reply} | {error, Reason}

Executes a synchronous call to a goat. This does not necessarily require the goat be active.

cast/2

cast(GoatId::goat_id(), Message::term()) -> ok | {error, Reason}

Executes an asynchronous cast to a goat. The goat will be activated as necessary.

delete/1

delete(GoatId::goat_id()) -> ok | {error, Reason}

Removes a goat from existence.

goat_handler/2

goat_handler(Handler::module(), GoatId::goat_id()) -> never_returns

Handles the dynamic aspect of a goat, as required. This function should not be called by user code.

new/2

new(Module::module(), State::state()) -> goat_id()

Equivalent to new(module(), state(), infinity).

new/3

new(Handler::module(), State::state(), Timeout::timeout()) -> goat_id()

Creates a new goat with the given handler module. The module should contain functions which will be called to react to all calls and casts sent to the goat.

start/0

start() -> ok

Starts the goat subsystem. Should be called before any other functions in this module are used.

stop/0

stop() -> ok

Stops the goat subsystem.


Generated by EDoc, Feb 18 2008, 06:47:48.