1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- -module(ebb_worker_bridge).
- -behaviour(supervisor_bridge).
- %% API
- -export([start_link/3, start_link/4]).
- %% supervisor_bridge callbacks
- -export([init/1, terminate/2]).
- -define(SERVER, ?MODULE).
- -record(state, {mode, worker}).
- %%====================================================================
- %% API
- %%====================================================================
- %%--------------------------------------------------------------------
- %% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
- %% Description: Starts the supervisor bridge
- %%--------------------------------------------------------------------
- start_link(Func, Args, Receiver) ->
- supervisor_bridge:start_link(?MODULE, {Func, Args, Receiver}).
- start_link(Node, Func, Args, Receiver) ->
- supervisor_bridge:start_link(?MODULE, {Node, Func, Args, Receiver}).
- %%====================================================================
- %% supervisor_bridge callbacks
- %%====================================================================
- %%--------------------------------------------------------------------
- %% Funcion: init(Args) -> {ok, Pid, State} |
- %% ignore |
- %% {error, Reason}
- %% Description:Creates a supervisor_bridge process, linked to the calling
- %% process, which calls Module:init/1 to start the subsystem. To ensure a
- %% synchronized start-up procedure, this function does not return until
- %% Module:init/1 has returned.
- %%--------------------------------------------------------------------
- init({Func, Args, Receiver}) ->
- case ebb_worker:start_link(Func, Args, Receiver) of
- {ok, Pid} ->
- {ok, Pid, #state{mode=local, worker=Pid}};
- Error ->
- Error
- end;
- init({Node, Func, Args, Receiver}) ->
- case ebb_worker:start_link(Node, Func, Args, Receiver) of
- {ok, Pid} ->
- {ok, Pid, #state{mode={distributed, Node}, worker=Pid}};
- Error ->
- Error
- end.
- %%--------------------------------------------------------------------
- %% Func: terminate(Reason, State) -> void()
- %% Description:This function is called by the supervisor_bridge when it is
- %% about to terminate. It should be the opposite of Module:init/1 and stop
- %% the subsystem and do any necessary cleaning up.The return value is ignored.
- %%--------------------------------------------------------------------
- terminate(normal, _State) ->
- ok;
- terminate(noconnection, #state{mode={distributed, Node}}) ->
- ebb_work_manager:remove_node(Node),
- exit(noconnection);
- terminate(Reason, _State) ->
- exit(Reason).
- %%====================================================================
- %% Internal functions
- %%====================================================================
|