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/gen_fsm.xml | 55 +++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 19 deletions(-)
(limited to 'lib/stdlib/doc/src/gen_fsm.xml')
diff --git a/lib/stdlib/doc/src/gen_fsm.xml b/lib/stdlib/doc/src/gen_fsm.xml
index 421eeb4fd3..73c1911f1e 100644
--- a/lib/stdlib/doc/src/gen_fsm.xml
+++ b/lib/stdlib/doc/src/gen_fsm.xml
@@ -84,9 +84,10 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
start_link(FsmName, Module, Args, Options) -> Result
Create a gen_fsm process in a supervision tree.
- FsmName = {local,Name} | {global,GlobalName}
+ FsmName = {local,Name} | {global,GlobalName}
+ | {via,Module,ViaName}
Name = atom()
- GlobalName = term()
+ GlobalName = ViaName = term()
Module = atom()
Args = term()
Options = [Option]
@@ -113,8 +114,16 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
locally as Name using register/2.
If FsmName={global,GlobalName}, the gen_fsm is
registered globally as GlobalName using
- global:register_name/2. If no name is provided,
- the gen_fsm is not registered.
+ global:register_name/2.
+ If EventMgrName={via,Module,ViaName}, the event manager will
+ register with the registry represented by Module.
+ The Module callback should export the functions
+ register_name/2, unregister_name/1,
+ whereis_name/1 and send/2, which should behave like the
+ corresponding functions in global. Thus,
+ {via,global,GlobalName} is a valid reference.
+ If no name is provided,
+ the gen_fsm 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.
@@ -154,9 +163,10 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
start(FsmName, Module, Args, Options) -> Result
Create a stand-alone gen_fsm process.
- FsmName = {local,Name} | {global,GlobalName}
+ FsmName = {local,Name} | {global,GlobalName}
+ | {via,Module,ViaName}
Name = atom()
- GlobalName = term()
+ GlobalName = ViaName = term()
Module = atom()
Args = term()
Options = [Option]
@@ -180,9 +190,10 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
send_event(FsmRef, Event) -> ok
Send an event asynchronously to a generic FSM.
- FsmRef = Name | {Name,Node} | {global,GlobalName} | pid()
+ FsmRef = Name | {Name,Node} | {global,GlobalName}
+ | {via,Module,ViaName} | pid()
Name = Node = atom()
- GlobalName = term()
+ GlobalName = ViaName = term()
Event = term()
@@ -196,9 +207,11 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
- the pid,
- Name, if the gen_fsm is locally registered,
- {Name,Node}, if the gen_fsm is locally
- registered at another node, or
- - {global,GlobalName}, if the gen_fsm is globally
- registered.
+ registered at another node, or
+ - {global,GlobalName}, if the gen_fsm is globally
+ registered.
+ - {via,Module,ViaName}, if the event manager is registered
+ through an alternative process registry.
Event is an arbitrary term which is passed as one of
the arguments to Module:StateName/2.
@@ -208,9 +221,10 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
send_all_state_event(FsmRef, Event) -> ok
Send an event asynchronously to a generic FSM.
- FsmRef = Name | {Name,Node} | {global,GlobalName} | pid()
+ FsmRef = Name | {Name,Node} | {global,GlobalName}
+ | {via,Module,ViaName} | pid()
Name = Node = atom()
- GlobalName = term()
+ GlobalName = ViaName = term()
Event = term()
@@ -232,9 +246,10 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
sync_send_event(FsmRef, Event, Timeout) -> Reply
Send an event synchronously to a generic FSM.
- FsmRef = Name | {Name,Node} | {global,GlobalName} | pid()
+ FsmRef = Name | {Name,Node} | {global,GlobalName}
+ | {via,Module,ViaName} | pid()
Name = Node = atom()
- GlobalName = term()
+ GlobalName = ViaName = term()
Event = term()
Timeout = int()>0 | infinity
Reply = term()
@@ -264,9 +279,10 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
sync_send_all_state_event(FsmRef, Event, Timeout) -> Reply
Send an event synchronously to a generic FSM.
- FsmRef = Name | {Name,Node} | {global,GlobalName} | pid()
+ FsmRef = Name | {Name,Node} | {global,GlobalName}
+ | {via,Module,ViaName} | pid()
Name = Node = atom()
- GlobalName = term()
+ GlobalName = ViaName = term()
Event = term()
Timeout = int()>0 | infinity
Reply = term()
@@ -388,9 +404,10 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
| {log_to_file,FileName} | {install,{Func,FuncState}}
StateName = atom()
StateData = term()
- FsmName = {local,Name} | {global,GlobalName}
+ FsmName = {local,Name} | {global,GlobalName}
+ | {via,Module,ViaName}
Name = atom()
- GlobalName = term()
+ GlobalName = ViaName = term()
Timeout = int() | infinity
--
cgit v1.2.3