Skip to content

Commit

Permalink
Add API for reading from and writing to the storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Tesla committed Jul 29, 2009
1 parent 8b37ddc commit d55ff8a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/mg_node_storage.erl
Expand Up @@ -3,6 +3,7 @@
-behaviour(gen_server).

%% API
-export([insert/1,lookup/1]).
-export([start_link/0]).

%% gen_server callbacks
Expand All @@ -19,6 +20,18 @@
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

insert(Record = {_Key, _Sequence}) ->
gen_server:call(?MODULE, {insert, Record});
insert(Records = [{_Key, _Sequence}|_]) ->
%% I'm willing to assume that if the first element is a tuple of the
%% shape we like, then the rest are.
gen_server:call(?MODULE, {insert, Records});
insert([]) ->
ok.

lookup(Key) ->
ets:lookup(?TABLE, Key).

%%====================================================================
%% gen_server callbacks
%%====================================================================
Expand All @@ -43,6 +56,10 @@ init([]) ->
%% {stop, Reason, State}
%% Description: Handling call messages
%%--------------------------------------------------------------------
handle_call({insert, ObjectOrObjects}, _From, State) ->
true = ets:insert(?TABLE, ObjectOrObjects),
{reply, ok, State};

handle_call(_Request, _From, State) ->
Reply = ok,
{reply, Reply, State}.
Expand Down

0 comments on commit d55ff8a

Please sign in to comment.