Guest User

Untitled

a guest
Jun 2nd, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.27 KB | None | 0 0
  1. -module(oka_oprek_agensrv).
  2. -behaviour(gen_server).
  3.  
  4. %% API
  5. -export([stop/0, start_link/0, hello/0, start_bgensrv/0]).
  6. -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
  7. -record(state, {dummy}).
  8.  
  9. start_link() ->
  10.   gen_server:start_link({local, agensrv}, ?MODULE, ["Oka Prinarjaya"], []).
  11.  
  12. stop() ->
  13.   gen_server:call(agensrv, stop).
  14.  
  15. hello() ->
  16.   gen_server:call(agensrv, hello).
  17.  
  18. start_bgensrv() ->
  19.   gen_server:call(agensrv, start_bgensrv).
  20.  
  21. init(ApaAja) ->
  22.   {ok, #state{dummy=ApaAja}}.
  23.  
  24. handle_call(stop, _From, State) ->
  25.   {stop, normal, stopped, State};
  26.  
  27. handle_call(hello, From, State) ->
  28.   {reply, {ok, hello, From}, State};
  29.  
  30. handle_call(start_bgensrv, From, State) ->
  31.   {ok, Pid} = oka_oprek_bgensrv:start_link(),
  32.   erlang:monitor(process, Pid),
  33.   {reply, {ok, start_bgensrv, From}, State}.
  34.  
  35. handle_cast(_Msg, State) ->
  36.   {noreply, State}.
  37.  
  38. handle_info({'DOWN', Ref, process, Pid, _Reason}, State) ->
  39.   io:format("Monitored process died. Ref=~p, Pid=~p~n", [Ref, Pid]),
  40.   {noreply, State};
  41.  
  42. handle_info({'EXIT', _Pid, _Reason}, State) ->
  43.   {noreply, State};
  44.  
  45. handle_info(_Info, State) ->
  46.   {noreply, State}.
  47.  
  48. terminate(_Reason, _State) ->
  49.   ok.
  50.  
  51. code_change(_OldVsn, State, _Extra) ->
  52.   {ok, State}.
Advertisement
Add Comment
Please, Sign In to add comment