commit | d8d21b3b66f0999af985f7f06d634e74860218e0 | [log] [tgz] |
---|---|---|
author | Takeru Ohta <phjgt308@gmail.com> | Tue Oct 07 02:18:39 2014 +0900 |
committer | Takeru Ohta <phjgt308@gmail.com> | Tue Oct 07 02:28:35 2014 +0900 |
tree | 4d27791f04aef1802d5b6c78a7ca6710b74db2d4 | |
parent | 1191c9973cf3e1e0b578036218b0767f34c8e4d5 [diff] |
Add local:otp_name/1 and local:which_processes/{1,2}
A Local Name Registration Facility.
The library provides the following features:
gen_server
(and other OTP behaviours) can use the registration facility through {via, local, local:name()}
formatted name# clone $ git clone git://github.com/sile/jsone.git $ cd local # compile $ make compile # run tests $ make eunit # dialyze $ make dialyze # Erlang shell $ make start 1> local:start(sample_name_server). ok
%% Starts name server > ok = local:start_name_server(sample_name_server). > local:which_name_servers(). [sample_name_server] %% Registers process name > self(). <0.42.0> > local:register_name({sample_name_server, hoge}, self()). % succeeded yes > local:register_name({sample_name_server, hoge}, self()). % failed: name collision no > local:whereis_name({sample_name_server, hoge}). <0.42.0> %% Registered name can be used as gen_server's via name > gen_server:cast({via, local, {sample_name_server, hoge}}, hello). ok > flush(). Shell got {'$gen_cast',hello} ok %% Unregisters process name > local:unregister_name({sample_name_server, hoge}). ok > local:whereis_name({sample_name_server, hoge}). undefined %% Stops name server > ok = local:stop_name_server(sample_name_server). > local:which_name_servers(). []
Local can be embedded in your application.
%% Embedding Example -module(your_app_sup). -behaviour(supervisor). -export([init/1]). % 'supervisor' callback API init([]) -> Child1 = local:name_server_child_spec(your_app_name_server_1), Child2 = local:name_server_child_spec(your_app_name_server_2), {ok, { {one_for_one, 5, 10}, [Child1, Child2]} }.
See EDoc Document