couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [04/35] git commit: Add an API to register for multiple DbNames
Date Fri, 01 Aug 2014 09:10:00 GMT
Add an API to register for multiple DbNames

Just a convenience thing for code that may want to listen to more than
one database's update notifications.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/commit/475af68c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/tree/475af68c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/diff/475af68c

Branch: refs/heads/windsor-merge
Commit: 475af68c2d99825efb4c492183ebdf5175a52fba
Parents: f4c80d7
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Apr 23 14:41:24 2013 -0500
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed Jul 30 17:35:36 2014 +0100

----------------------------------------------------------------------
 src/couch_event.erl          | 16 +++++++++++++---
 src/couch_event_registry.erl | 16 ++++++++--------
 2 files changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/blob/475af68c/src/couch_event.erl
----------------------------------------------------------------------
diff --git a/src/couch_event.erl b/src/couch_event.erl
index eaa4c88..ffee077 100644
--- a/src/couch_event.erl
+++ b/src/couch_event.erl
@@ -14,8 +14,10 @@
 
 -export([
     register/2,
+    register_many/2,
     register_all/1,
     unregister/2,
+    unregister_many/2,
     unregister_all/1,
     notify/2
 ]).
@@ -26,15 +28,23 @@
 
 
 register(Pid, DbName) ->
-    gen_server:call(?REGISTRY, {register, Pid, DbName}).
+    gen_server:call(?REGISTRY, {register, Pid, [DbName]}).
+
+
+register_many(Pid, DbNames) when is_list(DbNames) ->
+    gen_server:call(?REGISTRY, {register, Pid, DbNames}).
 
 
 register_all(Pid) ->
-    gen_server:call(?REGISTRY, {register, Pid, all_dbs}).
+    gen_server:call(?REGISTRY, {register, Pid, [all_dbs]}).
 
 
 unregister(Pid, DbName) ->
-    gen_server:call(?REGISTRY, {unregister, Pid, DbName}).
+    gen_server:call(?REGISTRY, {unregister, Pid, [DbName]}).
+
+
+unregister_many(Pid, DbNames) when is_list(DbNames) ->
+    gen_server:call(?REGISTRY, {unregister, Pid, DbNames}).
 
 
 unregister_all(Pid) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/blob/475af68c/src/couch_event_registry.erl
----------------------------------------------------------------------
diff --git a/src/couch_event_registry.erl b/src/couch_event_registry.erl
index e956a83..19e70c2 100644
--- a/src/couch_event_registry.erl
+++ b/src/couch_event_registry.erl
@@ -56,12 +56,10 @@ terminate(_Reason, _St) ->
     ok.
 
 
-handle_call({register, Pid, DbName}, _From, St) ->
-    Client = #client{
-        dbname = DbName,
-        pid = Pid
-    },
-    ets:insert(?REGISTRY_TABLE, Client),
+handle_call({register, Pid, DbNames}, _From, St) ->
+    lists:foreach(fun(DbName) ->
+        ets:insert(?REGISTRY_TABLE, #client{dbname=DbName, pid=Pid})
+    end, DbNames),
     case ets:lookup(?MONITOR_TABLE, Pid) of
         [] ->
             Ref = erlang:monitor(process, Pid),
@@ -71,8 +69,10 @@ handle_call({register, Pid, DbName}, _From, St) ->
     end,
     {reply, ok, St};
 
-handle_call({unregister, Pid, DbName}, _From, St) ->
-    unregister_pattern(#client{dbname=DbName, pid=Pid, _='_'}),
+handle_call({unregister, Pid, DbNames}, _From, St) ->
+    lists:foreach(fun(DbName) ->
+        unregister_pattern(#client{dbname=DbName, pid=Pid, _='_'})
+    end, DbNames),
     {reply, ok, St};
 
 handle_call({unregister_all, Pid}, _From, St) ->


Mime
View raw message