Permalink
Browse files

Merge branch 'r1711-ezk-asymmetric-error-behaviour'

  • Loading branch information...
2 parents 067e836 + 4ceac72 commit 24448ff0a0636395c287f39f8bb5c84287d336a0 @cvik cvik committed Jan 25, 2013
Showing with 575 additions and 558 deletions.
  1. +1 −1 src/ezk.app.src
  2. +43 −46 src/ezk.erl
  3. +265 −236 src/ezk_connection.erl
  4. +70 −70 src/ezk_connection_manager.erl
  5. +74 −80 src/ezk_highlander.erl
  6. +6 −7 src/ezk_log.erl
  7. +45 −49 src/ezk_message_2_packet.erl
  8. +71 −69 src/ezk_packet_2_message.erl
View
@@ -8,7 +8,7 @@
stdlib
]},
{mod, {ezk_app, []}},
- {env, [{default_servers,
+ {env, [{default_servers,
[{localhost, 2181, 30000, 10000},
{ localhost, 2182, 30000, 10000},
{ localhost, 2183, 30000, 10000}]
View
@@ -44,8 +44,8 @@
-export([add_monitors/2, get_connections/0]).
-export([exists/2, exists/4]).
--type ezk_err() :: inval_acl | dir_exists | no_rights | no_dir |
- childs_or_forbidden.
+-type ezk_err() :: inval_acl | dir_exists | no_rights | no_dir |
+ childs_or_forbidden.
-type ezk_path() :: string().
-type ezk_conpid() :: pid().
-type ezk_data() :: binary().
@@ -62,57 +62,54 @@
-type ezk_ls2data() :: {children, [ezk_path()]} | {getdata, ezk_getdata()}.
-type ezk_server() :: {}.
-type ezk_monitor() :: pid().
--type ezk_authreply() :: {ok, authed} | {error, auth_failed} |
- {error, unknown, binary()} | {error, auth_in_progress}.
+-type ezk_authreply() :: {ok, authed} | {error, auth_failed} |
+ {error, unknown, binary()} | {error, auth_in_progress}.
-spec create/3 :: (ezk_conpid(), ezk_path(), ezk_data()) ->
- {ok, ezk_path()} | {error, ezk_err()}.
+ {ok, ezk_path()} | {error, ezk_err()}.
-spec create/4 :: (ezk_conpid(), ezk_path(), ezk_data(), ezk_ctype()) ->
- {ok, ezk_path()} | {error, ezk_err()}.
+ {ok, ezk_path()} | {error, ezk_err()}.
-spec create/5 :: (ezk_conpid(), ezk_path(), ezk_data(), ezk_ctype(), ezk_acls()) ->
- {ok, ezk_path()} | {error, ezk_err()}.
+ {ok, ezk_path()} | {error, ezk_err()}.
-spec ensure_path/2 :: (ezk_conpid(), ezk_path()) ->
- {ok, ezk_path()} | {error, ezk_err()}.
+ {ok, ezk_path()} | {error, ezk_err()}.
-spec delete/2 :: (ezk_conpid(), ezk_path()) ->
- {ok, ezk_path()} | {error, ezk_err()}.
+ {ok, ezk_path()} | {error, ezk_err()}.
-spec delete_all/2 :: (ezk_conpid(), ezk_path()) ->
- {ok, ezk_path()} | {error, ezk_err()}.
+ {ok, ezk_path()} | {error, ezk_err()}.
-spec exists/2 :: (ezk_conpid(), ezk_path()) ->
- {ok, ezk_getdata()} | {error, ezk_err()}.
+ {ok, ezk_getdata()} | {error, ezk_err()}.
-spec exists/4 :: (ezk_conpid(), ezk_path(), ezk_watchowner(), ezk_watchmessage()) ->
- {ok, ezk_getdata()} | {error, ezk_err()}.
+ {ok, ezk_getdata()} | {error, ezk_err()}.
-spec ls/2 :: (ezk_conpid(), ezk_path()) ->
- {ok, [ezk_path()]} | {error, ezk_err()}.
+ {ok, [ezk_path()]} | {error, ezk_err()}.
-spec ls/4 :: (ezk_conpid(), ezk_path(), ezk_watchowner(), ezk_watchmessage()) ->
- {ok, [ezk_path()]} | {error, ezk_err()}.
+ {ok, [ezk_path()]} | {error, ezk_err()}.
-spec ls2/2 :: (ezk_conpid(), ezk_path()) ->
- {ok, [ezk_ls2data()]} | {error, ezk_err()}.
+ {ok, [ezk_ls2data()]} | {error, ezk_err()}.
-spec ls2/4 :: (ezk_conpid(), ezk_path(), ezk_watchowner(), ezk_watchmessage()) ->
- {ok, [ezk_ls2data()]} | {error, ezk_err()}.
+ {ok, [ezk_ls2data()]} | {error, ezk_err()}.
-spec get/2 :: (ezk_conpid(), ezk_path()) ->
- {ok, {ezk_data(), ezk_getdata()}} | {error, ezk_err()}.
+ {ok, {ezk_data(), ezk_getdata()}} | {error, ezk_err()}.
-spec get/4 :: (ezk_conpid(), ezk_path(), ezk_watchowner(), ezk_watchmessage()) ->
- {ok, {ezk_data(), ezk_getdata()}} | {error, ezk_err()}.
+ {ok, {ezk_data(), ezk_getdata()}} | {error, ezk_err()}.
-spec set/3 :: (ezk_conpid(), ezk_path(), ezk_data()) ->
- {ok, ezk_getdata()} | {error, ezk_err()}.
+ {ok, ezk_getdata()} | {error, ezk_err()}.
-spec set_acl/3:: (ezk_conpid(), ezk_path(), ezk_acls()) ->
- {ok, ezk_getdata()}.
+ {ok, ezk_getdata()}.
-spec get_acl/2:: (ezk_conpid, ezk_path()) ->
- {ok, {ezk_acls(), ezk_getdata()}}.
+ {ok, {ezk_acls(), ezk_getdata()}}.
-spec start_connection/0 :: () -> {ok, ezk_conpid()} | {error, no_server_reached}.
--spec start_connection/1 :: (ezk_server()) ->
- {ok, ezk_conpid()} |
- {error, no_server_reached}.
+-spec start_connection/1 :: ([ezk_server()]) ->
+ {ok, ezk_conpid()} |
+ {error, no_server_reached}.
-spec end_connection/2 :: (ezk_conpid(), string()) -> ok | {error, no_connection}.
-spec add_monitors/2 :: (ezk_conpid(), [pid()]) -> ok.
-spec get_connections/0 :: () -> [{ezk_conpid(), [ezk_monitor()]}].
-spec info_get_iterations/1 :: (ezk_conpid()) -> integer().
-spec auth/3 :: (ezk_conpid(), ezk_acl_scheme(), ezk_acl_id()) ->
- ezk_authreply().
-
-
-
+ ezk_authreply().
help() ->
io:format("--------------------------------------------------------------~n"),
@@ -155,7 +152,7 @@ help() ->
io:format("|------------------------------------------------------------|~n"),
io:format("| Datatypes: |~n"),
io:format("| Acl = {Scheme,Id, [Permission]} |~n"),
- io:format("| Path = Scheme = Id = Reason = String |~n"),
+ io:format("| Path = Scheme = Id = Reason = String |~n"),
io:format("| Permission = r | w | c | d | a |~n"),
io:format("| WatchOwner, ConPId = PId WatchMessage = String |~n"),
io:format("| Data = All Things Typ = e | s | es |~n"),
@@ -167,7 +164,7 @@ help() ->
%%--------------------------- Zookeeper Functions ---------------------
%% Return {ok, Reply}.
-%% Reply = authed
+%% Reply = authed
%% Returns {error, auth_in_progress} if the authslot is already in use.
%% Returns {error, auth_failed} if server rejected auth
%% Returns {error, unknown, ErrorCodeBin} if something new happened
@@ -189,9 +186,9 @@ n_create(ConnectionPId, Path, Data, Typ, Receiver, Tag) ->
ezk_connection:n_create(ConnectionPId, Path, Data, Typ, Receiver, Tag).
-%% Acls = [Acl] where Acl = {Permissions, Scheme, Id}
+%% Acls = [Acl] where Acl = {Permissions, Scheme, Id}
%% with Scheme and Id = String
-%% and Permission = [Per] | String
+%% and Permission = [Per] | String
%% where Per = r | w | c | d | a
create(ConnectionPId, Path, Data, Typ, Acls) ->
ezk_connection:create(ConnectionPId, Path, Data, Typ, Acls).
@@ -212,12 +209,12 @@ n_delete(ConnectionPId, Path, Receiver, Tag) ->
%% Deletes a ZK_Node and all his childs.
%% Reply = Path where Path = String
delete_all(ConnectionPId, Path) ->
- ezk_connection:delete_all(ConnectionPId, Path).
+ ezk_connection:delete_all(ConnectionPId, Path).
%% Looks if a Node exists
%% Reply = Parameters like in get (see one function below)
%% Can set a watch to the path
-%% which is triggered
+%% which is triggered
%% a) when path is erased if path existed.
%% b) when path is created if path did not exist.
exists(ConnectionPId, Path) ->
@@ -232,7 +229,7 @@ get(ConnectionPId, Path) ->
ezk_connection:get(ConnectionPId, Path).
n_get(ConnectionPId, Path, Receiver, Tag) ->
ezk_connection:n_get(ConnectionPId, Path, Receiver, Tag).
-
+
%% Like the one above but sets a datawatch to Path.
%% If watch is triggered a Message M is send to the PId WatchOwner
%% M = {WatchMessage, {Path, Type, SyncCon}}
@@ -268,7 +265,7 @@ ls(ConnectionPId, Path) ->
ezk_connection:ls(ConnectionPId, Path).
n_ls(ConnectionPId, Path, Receiver, Tag) ->
ezk_connection:n_ls(ConnectionPId, Path, Receiver, Tag).
-%% like above, but a Childwatch is set to the Node.
+%% like above, but a Childwatch is set to the Node.
%% Same Reaktion like at get with watch but Type = child
ls(ConnectionPId, Path, WatchOwner, WatchMessage) ->
ezk_connection:ls(ConnectionPId, Path, WatchOwner, WatchMessage).
@@ -279,7 +276,7 @@ ls2(ConnectionPId, Path) ->
ezk_connection:ls2(ConnectionPId, Path).
n_ls2(ConnectionPId, Path, Receiver, Tag) ->
ezk_connection:n_ls2(ConnectionPId, Path, Receiver, Tag).
-%% like above, but a Childwatch is set to the Node.
+%% like above, but a Childwatch is set to the Node.
%% Same Reaktion like at get with watch but Type = child
ls2(ConnectionPId, Path, WatchOwner, WatchMessage) ->
ezk_connection:ls2(ConnectionPId, Path, WatchOwner, WatchMessage).
@@ -288,35 +285,35 @@ ls2(ConnectionPId, Path, WatchOwner, WatchMessage) ->
%% Reply = Iteration = Int.
info_get_iterations(ConnectionPId) ->
ezk_connection:info_get_iterations(ConnectionPId).
-
+
%% Starts a connection to a zookeeper Server
-%% Returns {ok, PID} where Pid is the PId of the gen_server
+%% Returns {ok, PID} where Pid is the PId of the gen_server
%% which manages the connection
start_connection() ->
start_connection([]).
-
+
%% Starts a connection to a zookeeper Server
-%% Returns {ok, PID} where Pid is the PId of the gen_server
+%% Returns {ok, PID} where Pid is the PId of the gen_server
%% which manages the connection
start_connection(Servers) ->
ezk_connection_manager:start_connection(Servers).
-
+
%% stops a connection. Returns ok.
end_connection(ConnectionPId, Reason) ->
ezk_connection_manager:end_connection(ConnectionPId, Reason).
-%% Adds new monitor PIds to bind to one connection. If one
+%% Adds new monitor PIds to bind to one connection. If one
%% of the Monitors dies the connection is closed down.
add_monitors(ConnectionPId, Monitors) ->
ezk_connection_manager:add_monitors(ConnectionPId, Monitors).
-%% Provides a list of all actually active connections.
-%% Returns [Connection] where Connection = {PId, [MonitorPId]}
+%% Provides a list of all actually active connections.
+%% Returns [Connection] where Connection = {PId, [MonitorPId]}
get_connections() ->
ezk_connection_manager:get_connections().
die(ConnectionPId) ->
ezk:die(ConnectionPId, "No offence").
-die(ConnectionPId, Reason) ->
+die(ConnectionPId, Reason) when is_pid(ConnectionPId) ->
ezk_connection:die(ConnectionPId, Reason).
Oops, something went wrong.

0 comments on commit 24448ff

Please sign in to comment.