Skip to content

Commit

Permalink
support distributed interface, name space must be atom, not compatibe…
Browse files Browse the repository at this point in the history
…l with 0.x.x version
  • Loading branch information
Dmitry Kolesnikov committed May 14, 2013
1 parent f720e97 commit 91f59d7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
6 changes: 5 additions & 1 deletion Makefile
@@ -1,5 +1,9 @@
.PHONY: deps test

ifeq ($(id),)
export id=pts
endif

all: rebar deps compile

compile:
Expand All @@ -25,7 +29,7 @@ dialyzer: compile
@dialyzer -Wno_return -c apps/riak_kv/ebin

run:
erl -pa ./deps/*/ebin -pa ./ebin +P 10000000
erl -name ${id}@127.0.0.1 -setcookie nocookie -pa ./deps/*/ebin -pa ./ebin +P 10000000

rebar:
curl -O http://cloud.github.com/downloads/basho/rebar/rebar
Expand Down
2 changes: 1 addition & 1 deletion src/pts.app.src
@@ -1,7 +1,7 @@
{application, pts,
[
{description, "process term storage"},
{vsn, "0.7.0"},
{vsn, "1.0.0"},
{modules, [
pts,
pns,
Expand Down
31 changes: 16 additions & 15 deletions src/pts.erl
Expand Up @@ -47,6 +47,8 @@

%%
%% start new bucket
%% e.g.
%% {ok, _} = pts:start_link(cache, ['read-through', {entity, {pts_cache, start_link, [30000]}}])
-spec(start_link/2 :: (pts(), list()) -> {ok, pid()} | {error, any()}).

start_link(Name, Opts) ->
Expand All @@ -57,7 +59,7 @@ start_link(Name, Opts) ->
-spec(i/1 :: (atom()) -> list()).

i(Ns) ->
gen_server:call(pns:whereis(Ns), i).
gen_server:call(Ns, i).

%%
%% return meta data for given table
Expand All @@ -78,18 +80,18 @@ put(Ns, Key, Val) ->
pts:put(Ns, Key, Val, ?DEF_TIMEOUT).

put(Ns, Key, Val, Timeout) ->
gen_server:call(pns:whereis(Ns), {put, Key, Val}, Timeout).
gen_server:call(Ns, {put, Key, Val}, Timeout).

put_(Ns, Key, Val) ->
pts:put_(Ns, Key, Val, true).

put_(Ns, Key, Val, true) ->
Tx = erlang:make_ref(),
gen_server:cast(pns:whereis(Ns), {put, {tx, self(), Tx}, Key, Val}),
gen_server:cast(Ns, {put, {tx, self(), Tx}, Key, Val}),
Tx;

put_(Ns, Key, Val, false) ->
erlang:send(pns:whereis(Ns), {put, Key, Val}),
erlang:send(Ns, {put, Key, Val}),
ok.

%%
Expand All @@ -103,21 +105,20 @@ get(Ns, Key) ->
pts:get(Ns, Key, ?DEF_TIMEOUT).

get(Ns, Key, Timeout) ->
gen_server:call(pns:whereis(Ns), {get, Key}, Timeout).
gen_server:call(Ns, {get, Key}, Timeout).

get_(Ns, Key) ->
pts:get_(Ns, Key, true).

get_(Ns, Key, true) ->
Tx = erlang:make_ref(),
gen_server:cast(pns:whereis(Ns), {get, {tx, self(), Tx}, Key}),
gen_server:cast(Ns, {get, {tx, self(), Tx}, Key}),
Tx;

get_(Ns, Key, false) ->
erlang:send(pns:whereis(Ns), {get, Key}),
erlang:send(Ns, {get, Key}),
ok.


%%
%% remove value
-spec(remove/2 :: (atom(), any()) -> ok | {error, any()}).
Expand All @@ -129,18 +130,18 @@ remove(Ns, Key) ->
pts:remove(Ns, Key, ?DEF_TIMEOUT).

remove(Ns, Key, Timeout) ->
gen_server:call(pns:whereis(Ns), {remove, Key}, Timeout).
gen_server:call(Ns, {remove, Key}, Timeout).

remove_(Ns, Key) ->
pts:remove_(Ns, Key, true).

remove_(Ns, Key, true) ->
Tx = erlang:make_ref(),
gen_server:cast(pns:whereis(Ns), {remove, {tx, self(), Tx}, Key}),
gen_server:cast(Ns, {remove, {tx, self(), Tx}, Key}),
Tx;

remove_(Ns, Key, false) ->
erlang:send(pns:whereis(Ns), {remove, Key}),
erlang:send(Ns, {remove, Key}),
ok.

%%
Expand All @@ -149,24 +150,24 @@ remove_(Ns, Key, false) ->
-spec(call/4 :: (atom(), any(), any(), timeout()) -> any()).

call(Ns, Key, Msg) ->
gen_server:call(pns:whereis(Ns), {call, Key, Msg}).
gen_server:call(Ns, {call, Key, Msg}).

call(Ns, Key, Msg, Timeout) ->
gen_server:call(pns:whereis(Ns), {call, Key, Msg}, Timeout).
gen_server:call(Ns, {call, Key, Msg}, Timeout).

%%
%%
-spec(cast/3 :: (atom(), any(), any()) -> ok).

cast(Ns, Key, Msg) ->
gen_server:cast(pns:whereis(Ns), {cast, Key, Msg}).
gen_server:cast(Ns, {cast, Key, Msg}).

%%
%%
-spec(send/3 :: (atom(), any(), any()) -> any()).

send(Ns, Key, Msg) ->
erlang:send(pns:whereis(Ns), {send, Key, Msg}),
erlang:send(Ns, {send, Key, Msg}),
ok.

%%
Expand Down
3 changes: 1 addition & 2 deletions src/pts_ns.erl
Expand Up @@ -43,10 +43,9 @@
%%
%%
start_link(Sup, Name, Opts) ->
gen_server:start_link(?MODULE, [Sup, Name, Opts], []).
gen_server:start_link({local, Name}, ?MODULE, [Sup, Name, Opts], []).

init([Sup, Name, Opts]) ->
ok = pns:register(Name),
self() ! {set_factory, Sup}, % message to itself, avoid supervisor deadlock
{ok, init(Opts, #pts{name=Name})}.

Expand Down

0 comments on commit 91f59d7

Please sign in to comment.