diff --git a/src/rd_core.erl b/src/rd_core.erl index b8ea3f8..3b7d9ef 100644 --- a/src/rd_core.erl +++ b/src/rd_core.erl @@ -1,5 +1,5 @@ %%%------------------------------------------------------------------- -%%% @author Martin Logan +%%% @author Martin Logan %%% @copyright 2008 Erlware %%% @doc %%% Cache and distribute resources. @@ -52,7 +52,7 @@ -include("../include/resource_discovery.hrl"). --define(SERVER, ?MODULE). +-define(SERVER, ?MODULE). -record(state, {}). @@ -92,7 +92,7 @@ make_callbacks(NewResources) -> %%-------------------------------------------------------------------- -spec filter_resource_tuples_by_types([resource_type()], [resource_tuple()]) -> [resource_tuple()]. filter_resource_tuples_by_types(TargetTypes, Resources) -> - Fun = + Fun = fun({Type, _Instance} = Resource, Acc) -> case lists:member(Type, TargetTypes) of true -> [Resource|Acc]; @@ -182,7 +182,7 @@ trade_resources() -> -spec round_robin_get(resource_type()) -> {ok, resource()} | {error, not_found}. round_robin_get(Type) -> gen_server:call(?SERVER, {round_robin_get, Type}). - + %%-------------------------------------------------------------------- %% @doc %% Gets all cached resources of a given type @@ -198,7 +198,7 @@ all_of_type_get(Type) -> %%----------------------------------------------------------------------- %%-spec sync_resources(node(), {LocalResourceTuples, TargetTypes, DeletedTuples}) -> ok. sync_resources(Node, {LocalResourceTuples, TargetTypes, DeletedTuples}) -> - error_logger:info_msg("synch resources for node: ~p", [Node]), + %error_logger:info_msg("synch resources for node: ~p", [Node]), {ok, FilteredRemotes} = gen_server:call({?SERVER, Node}, {sync_resources, {LocalResourceTuples, TargetTypes, DeletedTuples}}), rd_store:store_resource_tuples(FilteredRemotes), make_callbacks(FilteredRemotes), @@ -256,12 +256,12 @@ init([]) -> {ok, #state{}}. handle_call({sync_resources, {Remotes, RemoteTargetTypes, RemoteDeletedTuples}}, _From, State) -> - error_logger:info_msg("sync_resources, got remotes: ~p deleted: ~p", [Remotes, RemoteDeletedTuples]), + %error_logger:info_msg("sync_resources, got remotes: ~p deleted: ~p", [Remotes, RemoteDeletedTuples]), LocalResourceTuples = rd_store:get_local_resource_tuples(), TargetTypes = rd_store:get_target_resource_types(), FilteredRemotes = filter_resource_tuples_by_types(TargetTypes, Remotes), FilteredLocals = filter_resource_tuples_by_types(RemoteTargetTypes, LocalResourceTuples), - error_logger:info_msg("sync_resources, storing filted remotes: ~p", [FilteredRemotes]), + %error_logger:info_msg("sync_resources, storing filted remotes: ~p", [FilteredRemotes]), rd_store:store_resource_tuples(FilteredRemotes), [rd_store:delete_resource_tuple(DR) || DR <- RemoteDeletedTuples], make_callbacks(FilteredRemotes), @@ -327,14 +327,14 @@ handle_cast(trade_resources, State) -> rd_store:delete_deleted_resource_tuple(), {noreply, State}; handle_cast({trade_resources, {ReplyTo, {Remotes, RemoteDeletedTuples}}}, State) -> - error_logger:info_msg("trade_resources, got remotes ~p: deleted: ~p", [Remotes, RemoteDeletedTuples]), + %error_logger:info_msg("trade_resources, got remotes ~p: deleted: ~p", [Remotes, RemoteDeletedTuples]), Locals = rd_store:get_local_resource_tuples(), LocalsDeleted = rd_store:get_deleted_resource_tuples(), TargetTypes = rd_store:get_target_resource_types(), FilteredRemotes = filter_resource_tuples_by_types(TargetTypes, Remotes), - error_logger:info_msg("got remotes and filtered ~p", [FilteredRemotes]), + %error_logger:info_msg("got remotes and filtered ~p", [FilteredRemotes]), rd_store:store_resource_tuples(FilteredRemotes), - error_logger:info_msg("trade_resources, deleting ~p", [RemoteDeletedTuples]), + %error_logger:info_msg("trade_resources, deleting ~p", [RemoteDeletedTuples]), [rd_store:delete_resource_tuple(DR) || DR <- RemoteDeletedTuples], make_callbacks(FilteredRemotes), reply(ReplyTo, {Locals, LocalsDeleted}), diff --git a/src/rd_util.erl b/src/rd_util.erl index ba87e45..4205a77 100644 --- a/src/rd_util.erl +++ b/src/rd_util.erl @@ -30,33 +30,33 @@ do_until(F, [H|T]) -> false -> do_until(F, T); Return -> Return end. - + %% @doc Pings a node and returns only after the net kernal distributes the nodes. -spec sync_ping(node(), timeout()) -> pang | pong. sync_ping(Node, Timeout) -> - error_logger:info_msg("pinging node: ~p", [Node]), + %%error_logger:info_msg("pinging node: ~p", [Node]), case net_adm:ping(Node) of pong -> - Resp = - poll_until(fun() -> - length(get_remote_nodes(Node)) == length(nodes()) - end, + Resp = + poll_until(fun() -> + length(get_remote_nodes(Node)) == length(nodes()) + end, 10, Timeout div 10), case Resp of true -> pong; false -> pang end; - pang -> + pang -> pang end. %% @doc This is a higher order function that allows for Iterations -%% number of executions of Fun until false is not returned +%% number of executions of Fun until false is not returned %% from the Fun pausing for PauseMS after each execution. %%
%% Variables: %% Fun - A fun to execute per iteration. -%% Iterations - The maximum number of iterations to try getting Reply out of Fun. +%% Iterations - The maximum number of iterations to try getting Reply out of Fun. %% PauseMS - The number of miliseconds to wait inbetween each iteration. %% Return - What ever the fun returns. %%@@ -65,13 +65,13 @@ poll_until(Fun, 0, _PauseMS) -> Fun(); poll_until(Fun, Iterations, PauseMS) -> case Fun() of - false -> + false -> timer:sleep(PauseMS), - case Iterations of + case Iterations of infinity -> poll_until(Fun, Iterations, PauseMS); Iterations -> poll_until(Fun, Iterations - 1, PauseMS) end; - Reply -> + Reply -> Reply end. @@ -82,7 +82,7 @@ get_env(Key, Default) -> {ok, Value} -> {ok, Value}; undefined -> {ok, Default} end. - + %%%=================================================================== @@ -93,11 +93,10 @@ get_env(Key, Default) -> get_remote_nodes(Node) -> try Nodes = rpc:call(Node, erlang, nodes, []), - error_logger:info_msg("contact node has ~p", [Nodes]), + %%error_logger:info_msg("contact node has ~p", [Nodes]), Nodes catch _C:E -> error_logger:info_msg("failed to connect to contact node ~p", [Node]), throw(E) end. - diff --git a/src/resource_discovery.erl b/src/resource_discovery.erl index bb1c6ea..49ff058 100644 --- a/src/resource_discovery.erl +++ b/src/resource_discovery.erl @@ -1,7 +1,7 @@ %%%------------------------------------------------------------------- %%% File : resource_discovery.erl %%% Author : Martin J. Logan
%% Varibles: @@ -339,8 +339,8 @@ ping_contact_nodes(Nodes, Timeout) -> -spec rpc_call(resource_type(), atom(), atom(), [term()], timeout()) -> term() | {error, not_found}. rpc_call(Type, Module, Function, Args, Timeout) -> case get_resource(Type) of - {ok, Resource} -> - error_logger:info_msg("got a resource ~p", [Resource]), + {ok, Resource} -> + %%error_logger:info_msg("got a resource ~p", [Resource]), case rpc:call(Resource, Module, Function, Args, Timeout) of {badrpc, Reason} -> error_logger:info_msg("got a badrpc ~p", [Reason]), @@ -358,8 +358,8 @@ rpc_call(Type, Module, Function, Args) -> rpc_call(Type, Module, Function, Args, 60000). %%------------------------------------------------------------------------------ -%% @doc Execute an rpc on a cached resource. Any bad nodes are deleted. -%% resource is deleted and the next resource is tried, else the result is +%% @doc Execute an rpc on a cached resource. Any bad nodes are deleted. +%% resource is deleted and the next resource is tried, else the result is %% returned to the user. %% @end %%------------------------------------------------------------------------------ @@ -367,8 +367,8 @@ rpc_call(Type, Module, Function, Args) -> rpc_multicall(Type, Module, Function, Args, Timeout) -> case get_resources(Type) of [] -> {error, no_resources}; - Resources -> - error_logger:info_msg("got resources ~p", [Resources]), + Resources -> + %%error_logger:info_msg("got resources ~p", [Resources]), {Resl, BadNodes} = rpc:multicall(Resources, Module, Function, Args, Timeout), [delete_resource_tuple({Type, BadNode}) || BadNode <- BadNodes], {Resl, BadNodes}