Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(oka_oprek_agensrv).
- -behaviour(gen_server).
- %% API
- -export([stop/0, start_link/0, hello/0, start_bgensrv/0]).
- -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
- -record(state, {dummy}).
- start_link() ->
- gen_server:start_link({local, agensrv}, ?MODULE, ["Oka Prinarjaya"], []).
- stop() ->
- gen_server:call(agensrv, stop).
- hello() ->
- gen_server:call(agensrv, hello).
- start_bgensrv() ->
- gen_server:call(agensrv, start_bgensrv).
- init(ApaAja) ->
- {ok, #state{dummy=ApaAja}}.
- handle_call(stop, _From, State) ->
- {stop, normal, stopped, State};
- handle_call(hello, From, State) ->
- {reply, {ok, hello, From}, State};
- handle_call(start_bgensrv, From, State) ->
- {ok, Pid} = oka_oprek_bgensrv:start_link(),
- erlang:monitor(process, Pid),
- {reply, {ok, start_bgensrv, From}, State}.
- handle_cast(_Msg, State) ->
- {noreply, State}.
- handle_info({'DOWN', Ref, process, Pid, _Reason}, State) ->
- io:format("Monitored process died. Ref=~p, Pid=~p~n", [Ref, Pid]),
- {noreply, State};
- handle_info({'EXIT', _Pid, _Reason}, State) ->
- {noreply, State};
- handle_info(_Info, State) ->
- {noreply, State}.
- terminate(_Reason, _State) ->
- ok.
- code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
Advertisement
Add Comment
Please, Sign In to add comment