Skip to content

Instantly share code, notes, and snippets.

@redink
Last active August 29, 2015 14:01
Show Gist options
  • Save redink/bc5eaf2d4f39b54017e2 to your computer and use it in GitHub Desktop.
Save redink/bc5eaf2d4f39b54017e2 to your computer and use it in GitHub Desktop.
-module(single_session).
-behaviour(gen_server).
%% API
-export([start_link/0]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
-define(MNESIA, 'mnesia@127.0.0.1').
-record(user, {userid, pid}).
-record(state, {}).
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
init([]) ->
{ok, #state{}}.
handle_call({set, A}, _, State) ->
{ok, Pid} = test_instance:start_link(),
lager:debug("____~p",[rpc:call(?MNESIA, session_manager, set, [{A, Pid, node()}])]),
{reply, ok, State};
handle_call({get, A}, _, State) ->
P =
case rpc:call(?MNESIA, session_manager, get, [{A}]) of
[] ->
undefined;
[#user{pid = {Pid, _}}] ->
Pid
end,
{reply, P, State};
handle_call(_Request, _From, State) ->
Reply = ok,
{reply, Reply, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
handle_info(_Info, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment