From b0426732cc19598f0c0c310b1e79918252495259 Mon Sep 17 00:00:00 2001
From: Ulf Wiger
Date: Mon, 17 Jan 2011 15:47:00 +0100
Subject: Add plugin support for alternative name lookup
OTP behaviour instances (gen_server, gen_fsm, gen_event) can currently
register themselves either locally or globally, and the behaviour
libraries (including gen.erl) support both addressing methods, as well
as the normal Pid and {Name, Node}.
However, there are alternative registry implementations - e.g. gproc -
and one can well imagine other ways of locating a behaviour instance,
e.g. on a node connected only via a TCP tunnel, rather than via
Distributed Erlang. In all these cases, one needs to write extra code
to identify the behaviour instance, even though the instance itself
need not be aware of how it is located.
This patch introduces a new way of locating a behaviour instance:
{via, Module, Name}.
Module is expected to export a subset of the functions in global.erl,
namely:
register_name(Name, Pid) -> yes | no
whereis_name(Name) -> pid() | undefined
unregister_name(Name) -> ok
send(Name, Msg) -> Pid
Semantics are expected to be the same as for global.erl
This can be used in all places where {global, Name} is accepted.
faulty export in gen_fsm_SUITE.erl
await process death in dummy_via:reset()
fix error in gen_[server|fsm]:enter_loop()
fix documentation
---
lib/stdlib/doc/src/supervisor.xml | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
(limited to 'lib/stdlib/doc/src/supervisor.xml')
diff --git a/lib/stdlib/doc/src/supervisor.xml b/lib/stdlib/doc/src/supervisor.xml
index cddb55e5c5..73df7183e6 100644
--- a/lib/stdlib/doc/src/supervisor.xml
+++ b/lib/stdlib/doc/src/supervisor.xml
@@ -271,8 +271,14 @@ child_spec() = {Id,StartFunc,Restart,Shutdown,Type,Modules}
If SupName={local,Name} the supervisor is registered
locally as Name using register/2. If
SupName={global,Name} the supervisor is registered
- globally as Name using global:register_name/2.
- If no name is provided, the supervisor is not registered.
+ globally as Name using global:register_name/2. If
+ SupName={via,Module,Name} the supervisor
+ is registered as Name using the registry represented by
+ Module. The Module callback should export the functions
+ register_name/2, unregister_name/1 and send/2,
+ which should behave like the corresponding functions in global.
+ Thus, {via,global,Name} is a valid reference.
+ If no name is provided, the supervisor is not registered.
Module is the name of the callback module.
Args is an arbitrary term which is passed as
the argument to Module:init/1.
@@ -315,6 +321,8 @@ child_spec() = {Id,StartFunc,Restart,Shutdown,Type,Modules}
registered at another node, or
- {global,Name}, if the supervisor is globally
registered.
+ - {via,Module,Name}, if the supervisor is registered
+ through an alternative process registry.
ChildSpec should be a valid child specification
(unless the supervisor is a simple_one_for_one
--
cgit v1.2.3