Commits

Anonymous committed a092ca3

Change Jiak to use new riak_client.

Comments (0)

Files changed (3)

demo/stickynotes/src/stickynotes_sup.erl

 %% @doc notes and groups know how to deal with Riak siblings,
 %%      so we'll turn on allow_mult for them
 setup_buckets(RiakConfig) ->
-    code:add_path("../../ebin"), %% riak ebin for jiak module
-    case jiak:client_connect(
-           proplists:get_value(riak_hostname, RiakConfig),
-           proplists:get_value(doorbell_port, RiakConfig),
-           proplists:get_value(riak_cookie, RiakConfig)) of
+    code:add_path("../../ebin"), %% riak ebin for jiak module    
+    Node = to_node(proplists:get_value(riak_nodename, RiakConfig), proplists:get_value(riak_hostname, RiakConfig)),
+    Cookie = proplists:get_value(riak_cookie, RiakConfig),
+    erlang:set_cookie(node(), Cookie),
+    case jiak:client_connect(Node) of
         {ok, C} ->
             C:set_bucket(<<"notes">>, [{bucket_mod, notes},{allow_mult, true}]),
             C:set_bucket(<<"groups">>, [{bucket_mod, groups},{allow_mult, true}]);
         Error ->
             error_logger:error_msg(
-              "Unable to connect to riak cluster at ~p:~p"
+              "Unable to connect to riak cluster at ~s"
               " with cookie ~p~nError: ~p",
-              [proplists:get_value(riak_hostname, RiakConfig),
-               proplists:get_value(doorbell_port, RiakConfig),
-               proplists:get_value(riak_cookie, RiakConfig),
-               Error])
+              [Node, Cookie, Error])
     end.
+    
+to_node(Nodename, Hostname) ->
+    list_to_atom(atom_to_list(Nodename) ++ "@" ++ Hostname).
+    
 %%      links for following.
 -module(jiak).
 
--export([local_client/0,
-         client_connect/3, client_connect/4]).
+-export([local_client/0, client_connect/1]).
 -export([default_jiak_bucket_props/0]).
 -export([standard_sibling_merge/1]).
 
 %% @spec local_client() -> {ok, jiak_client()}|error_term()
 %% @doc Open a Riak client for modifying Jiak objects.
 %% @see riak:local_client/0
-local_client() ->
-    {ok, C} = riak:local_client(),
-    {ok, jiak_client:new(C)}.
+local_client() -> riak:local_client().
 
-%% @spec client_connect(IP :: list(), Port :: integer(), RiakCookie :: atom())
-%%        -> {ok, Client :: jiak_client()} | {error, timeout}
+%% @spec client_connect(Node :: node())
+%%        -> {ok, Client :: jiak_client()} | exception
 %% @doc The usual way to get a client.  Timeout often means either a bad
 %%      cookie or a poorly-connected distributed erlang network.
-client_connect(IP,Port,RiakCookie)->
-    client_connect(IP, Port, RiakCookie, 1000).
-
-%% @spec client_connect(IP :: list(), Port :: integer(), RiakCookie :: atom(),
-%%                      TimeoutMillisecs :: integer())
-%%        -> {ok, Client :: jiak_client()} | {error, timeout}
-%% @doc The usual way to get a client.  Timeout often means either a bad
-%%      cookie or a poorly-connected distributed erlang network.
-client_connect(IP,Port,RiakCookie,Timeout) ->
-    case riak:client_connect(IP,Port,RiakCookie,Timeout) of
-        {ok, C} -> {ok, jiak_client:new(C)};
-        Error   -> Error
-    end.
+client_connect(Node) -> riak:client_connect(Node).
 
 %% @spec default_jiak_bucket_props() -> [bucket_prop()]
 %% @doc Returns the default additional bucket parameters for Jiak
 client_connect(Node) -> 
     % Make sure we can reach this node...
     case net_adm:ping(Node) of
-        pang -> throw({could_not_reach_node, Node});
-        pong -> ok
-    end,
-        
-    % Return the newly created node...
-    {ok, riak_client:new(Node, riak_util:mkclientid(Node))}.
-
+        pang -> {error, {could_not_reach_node, Node}};
+        pong -> {ok, riak_client:new(Node, riak_util:mkclientid(Node))}
+    end.
 
 
 %% @spec ensure_started(Application :: atom()) -> ok
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.