endpoint alias name use gproc
This commit is contained in:
parent
6abfbbc03a
commit
60a3fe9af4
@ -47,7 +47,7 @@ get_alias_name(Name) when is_binary(Name) ->
|
|||||||
|
|
||||||
-spec get_alias_pid(Name :: binary()) -> undefined | pid().
|
-spec get_alias_pid(Name :: binary()) -> undefined | pid().
|
||||||
get_alias_pid(Name) when is_binary(Name) ->
|
get_alias_pid(Name) when is_binary(Name) ->
|
||||||
iot_name_server:whereis_alias(get_alias_name(Name)).
|
gproc:whereis_name({n, l, get_alias_name(Name)}).
|
||||||
|
|
||||||
-spec forward(Pid :: pid(), ServiceId :: binary(), Metric :: binary()) -> no_return().
|
-spec forward(Pid :: pid(), ServiceId :: binary(), Metric :: binary()) -> no_return().
|
||||||
forward(Pid, ServiceId, Metric) when is_pid(Pid), is_binary(ServiceId), is_binary(Metric) ->
|
forward(Pid, ServiceId, Metric) when is_pid(Pid), is_binary(ServiceId), is_binary(Metric) ->
|
||||||
|
|||||||
@ -46,7 +46,7 @@ start_link(LocalName, AliasName, Endpoint = #endpoint{config = #http_endpoint{}}
|
|||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([AliasName, Endpoint]) ->
|
init([AliasName, Endpoint]) ->
|
||||||
Buffer = endpoint_buffer:new(Endpoint, 10),
|
Buffer = endpoint_buffer:new(Endpoint, 10),
|
||||||
iot_name_server:register(AliasName, self()),
|
true = gproc:reg({n, l, AliasName}),
|
||||||
{ok, #state{endpoint = Endpoint, buffer = Buffer}}.
|
{ok, #state{endpoint = Endpoint, buffer = Buffer}}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
|
|||||||
@ -51,8 +51,9 @@ start_link(LocalName, AliasName, Endpoint = #endpoint{}) when is_atom(LocalName)
|
|||||||
%% gen_statem:start_link/[3,4], this function is called by the new
|
%% gen_statem:start_link/[3,4], this function is called by the new
|
||||||
%% process to initialize.
|
%% process to initialize.
|
||||||
init([AliasName, Endpoint = #endpoint{id = Id}]) ->
|
init([AliasName, Endpoint = #endpoint{id = Id}]) ->
|
||||||
iot_name_server:register(AliasName, self()),
|
|
||||||
erlang:process_flag(trap_exit, true),
|
erlang:process_flag(trap_exit, true),
|
||||||
|
true = gproc:reg({n, l, AliasName}),
|
||||||
|
|
||||||
%% 创建转发器, 避免阻塞当前进程的创建,因此采用了延时初始化的机制
|
%% 创建转发器, 避免阻塞当前进程的创建,因此采用了延时初始化的机制
|
||||||
erlang:start_timer(0, self(), connect),
|
erlang:start_timer(0, self(), connect),
|
||||||
%% 初始化存储
|
%% 初始化存储
|
||||||
|
|||||||
@ -53,8 +53,8 @@ start_link(LocalName, AliasName, Endpoint = #endpoint{}) when is_atom(LocalName)
|
|||||||
%% gen_statem:start_link/[3,4], this function is called by the new
|
%% gen_statem:start_link/[3,4], this function is called by the new
|
||||||
%% process to initialize.
|
%% process to initialize.
|
||||||
init([AliasName, Endpoint]) ->
|
init([AliasName, Endpoint]) ->
|
||||||
iot_name_server:register(AliasName, self()),
|
|
||||||
erlang:process_flag(trap_exit, true),
|
erlang:process_flag(trap_exit, true),
|
||||||
|
true = gproc:reg({n, l, AliasName}),
|
||||||
%% 创建转发器, 避免阻塞当前进程的创建,因此采用了延时初始化的机制
|
%% 创建转发器, 避免阻塞当前进程的创建,因此采用了延时初始化的机制
|
||||||
erlang:start_timer(0, self(), create_postman),
|
erlang:start_timer(0, self(), create_postman),
|
||||||
%% 初始化存储
|
%% 初始化存储
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user