You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:00:52 UTC

[33/50] git commit: Provide a rexi:cast that uses erlang:send/2

Provide a rexi:cast that uses erlang:send/2

Sometimes we want to have workers avoid deferring their casts to a
temporary process. This can lead to message pileups on the distribution
control sockets.

BugzID: 13469


Project: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/commit/c6b77781
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/tree/c6b77781
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/diff/c6b77781

Branch: refs/heads/import
Commit: c6b77781da5cf48917c3bb45901176d56725194f
Parents: 42df8e4
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Apr 17 11:30:53 2012 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Apr 17 11:32:36 2012 -0500

----------------------------------------------------------------------
 src/rexi.erl | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-rexi/blob/c6b77781/src/rexi.erl
----------------------------------------------------------------------
diff --git a/src/rexi.erl b/src/rexi.erl
index bf1c2ab..93d33d7 100644
--- a/src/rexi.erl
+++ b/src/rexi.erl
@@ -14,7 +14,7 @@
 
 -module(rexi).
 -export([start/0, stop/0, restart/0]).
--export([cast/2, cast/3, kill/2]).
+-export([cast/2, cast/3, cast/4, kill/2]).
 -export([reply/1, sync_reply/1, sync_reply/2]).
 -export([async_server_call/2, async_server_call/3]).
 -export([get_errors/0, get_last_error/0, set_error_limit/1]).
@@ -63,6 +63,23 @@ cast(Node, Caller, MFA) ->
     rexi_utils:send({?SERVER, Node}, Msg),
     Ref.
 
+%% @doc Executes apply(M, F, A) on Node.
+%% This version accepts a sync option which uses the erlang:send/2 call
+%% directly in process instead of deferring to a spawned process if
+%% erlang:send/2 were to block. If the sync option is omitted this call
+%% is identical to cast/3.
+-spec cast(node(), pid(), {atom(), atom(), list()}, [atom()]) -> reference().
+cast(Node, Caller, MFA, Options) ->
+    case lists:member(sync, Options) of
+        true ->
+            Ref = make_ref(),
+            Msg = cast_msg({doit, {Caller, Ref}, get(nonce), MFA}),
+            erlang:send({?SERVER, Node}, Msg),
+            Ref;
+        false ->
+            cast(Node, Caller, MFA)
+    end.
+
 %% @doc Sends an async kill signal to the remote process associated with Ref.
 %% No rexi_EXIT message will be sent.
 -spec kill(node(), reference()) -> ok.