This commit is contained in:
anlicheng 2025-08-17 00:55:59 +08:00
parent 9599185742
commit 706c164163
5 changed files with 10 additions and 8 deletions

View File

@ -39,14 +39,16 @@ get_name(Id) when is_integer(Id) ->
list_to_atom("endpoint:" ++ integer_to_list(Id)).
-spec get_pid(Id :: integer()) -> undefined | pid().
get_pid(Id) when is_binary(Id) ->
get_pid(Id) when is_integer(Id) ->
whereis(get_name(Id)).
-spec get_alias_name(Name :: binary()) -> atom().
get_alias_name(Name) when is_binary(Name) ->
list_to_atom("endpoint:" ++ binary_to_list(Name)).
-spec get_alias_pid(Name :: binary()) -> undefined | pid().
get_alias_pid(Name) when is_binary(Name) ->
global:whereis_name(get_alias_name(Name)).
iot_name_server:whereis_alias(get_alias_name(Name)).
-spec forward(Pid :: pid(), ServiceId :: binary(), Format :: binary(), Metric :: binary()) -> no_return().
forward(Pid, ServiceId, Format, Metric) when is_pid(Pid), is_binary(ServiceId), is_binary(Format), is_binary(Metric) ->

View File

@ -29,7 +29,7 @@ start_link() ->
%% modules => modules()} % optional
init([]) ->
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
{ok, Endpoints} = endpoint_bo:get_all_endpoints(),
Endpoints = endpoint_bo:get_all_endpoints(),
ChildSpecs = lists:flatmap(fun(EndpointInfo) ->
case endpoint_bo:endpoint_record(EndpointInfo) of
error ->

View File

@ -54,7 +54,7 @@ handle_request("POST", "/endpoint/stop", _, #{<<"id">> := Id}) when is_integer(I
{ok, 200, iot_util:json_error(404, <<"endpoint not found">>)};
{ok, _} ->
case endpoint_sup:delete_endpoint(Id) of
{ok, Pid} when is_pid(Pid) ->
ok ->
{ok, 200, iot_util:json_data(<<"success">>)};
{error, Reason} ->
lager:warning("[endpoint_handler] stop endpoint id: ~p, get error: ~p", [Id, Reason]),

View File

@ -350,7 +350,7 @@ handle_event(cast, {handle, {data, #data{service_id = ServiceId, device_uuid = D
case iot_device:is_activated(Device) of
true ->
RouteKey = get_route_key(RouteKey0),
case endpoint:get_pid(RouteKey) of
case endpoint:get_alias_pid(RouteKey) of
undefined ->
ok;
EndpointPid ->

View File

@ -13,7 +13,7 @@
%% API
-export([start_link/0]).
-export([whereis/1, register/2]).
-export([whereis_alias/1, register/2]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
@ -35,8 +35,8 @@
register(Name, Pid) when is_atom(Name), is_pid(Pid) ->
gen_server:call(?SERVER, {register, Name, Pid}).
-spec whereis(Name :: atom()) -> undefined | pid().
whereis(Name) when is_atom(Name) ->
-spec whereis_alias(Name :: atom()) -> undefined | pid().
whereis_alias(Name) when is_atom(Name) ->
case ets:lookup(?TAB, Name) of
[] ->
undefined;