summaryrefslogtreecommitdiff
path: root/merge/src/merge_fetch_newentries.erl
blob: b45aaecc5a250c5d02ed7afc54104828f03f2487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%%% Copyright (c) 2017, NORDUnet A/S.
%%% See LICENSE for licensing information.

-module(merge_fetch_newentries).
-behaviour(gen_server).

-export([start_link/1, loop/3]).
-export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2,
         code_change/3]).

start_link(Args) ->
    gen_server:start_link(?MODULE, Args, []).

init({Name, Address, Period}) ->
    lager:info("~p:~p starting", [?MODULE, Name]),
    ChildPid = spawn_link(?MODULE, loop, [Name, Address, Period]),
    {ok, ChildPid}.

handle_call(stop, _From, ChildPid) ->
    lager:info("~p: stopping child process ~p", [?MODULE, ChildPid]),
    exit(ChildPid, stop),
    {stop, normal, stopped, nil}.

loop(Name, Address, Period) ->
    lager:info("~p:~p: asking storage node at ~p for missing entries",
              [?MODULE, Name, Address]),
    receive after Period -> ok end,
    loop(Name, Address, Period).

handle_cast(_Request, State) ->
    {noreply, State}.
handle_info(_Info, State) ->
    {noreply, State}.
code_change(_OldVsn, State, _Extra) ->
    {ok, State}.
terminate(_Reason, _State) ->
    lager:info("~p terminating", [?MODULE]),
    ok.