]> granicus.if.org Git - ejabberd/commitdiff
* src/odbc/ejabberd_odbc.erl: Load-balance ODBC requests between
authorAlexey Shchepin <alexey@process-one.net>
Wed, 29 Dec 2004 23:10:14 +0000 (23:10 +0000)
committerAlexey Shchepin <alexey@process-one.net>
Wed, 29 Dec 2004 23:10:14 +0000 (23:10 +0000)
several connections

* src/odbc/ejabberd_odbc_sup.erl: Supervisor for ODBC connections

* src/mod_muc/mod_muc_room.erl: Added missed type='form' attribute
in room configuration response (thanks to Badlop)

SVN Revision: 295

ChangeLog
src/mod_muc/mod_muc_room.erl
src/odbc/ejabberd_odbc.erl
src/odbc/ejabberd_odbc_sup.erl [new file with mode: 0644]

index d72d4bb3863ef975d33ad97c596d0bba36c27050..6fc3de883aa734e7fadac469f7f8bde1aa316867 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-12-30  Alexey Shchepin  <alexey@sevcom.net>
+
+       * src/odbc/ejabberd_odbc.erl: Load-balance ODBC requests between
+       several connections
+
+       * src/odbc/ejabberd_odbc_sup.erl: Supervisor for ODBC connections
+
+       * src/mod_muc/mod_muc_room.erl: Added missed type='form' attribute
+       in room configuration response (thanks to Badlop)
+
 2004-12-19  Alexey Shchepin  <alexey@sevcom.net>
 
        * src/mod_roster_odbc.erl: Roster support via ODBC (not completed)
index f41c4532e6afca92fa4395a1535abad18acc1c6b..bc1563d690bc2559d1310eb1ed34fe89143730ab 100644 (file)
@@ -1970,7 +1970,10 @@ get_config(Lang, StateData) ->
               [{xmlcdata,
                 translate:translate(
                   Lang, "You need an x:data capable client to configure room")}]}, 
-             {xmlelement, "x", [{"xmlns", ?NS_XDATA}], Res}], StateData}.
+             {xmlelement, "x", [{"xmlns", ?NS_XDATA},
+                                {"type", "form"}],
+              Res}],
+     StateData}.
 
 
 
index c496bf2be5b187f545ff03aa9e325e3aaf35f3d1..3800d141e5a6438094c62a97ddbf5337f6944e84 100644 (file)
 %%% API
 %%%----------------------------------------------------------------------
 start() ->
-    gen_server:start({local, ejabberd_odbc}, ejabberd_odbc, [], []).
+    gen_server:start(ejabberd_odbc, [], []).
 
 start_link() ->
-    gen_server:start_link({local, ejabberd_odbc}, ejabberd_odbc, [], []).
+    gen_server:start_link(ejabberd_odbc, [], []).
 
 sql_query(Query) ->
-    gen_server:call(ejabberd_odbc, {sql_query, Query}, 60000).
+    gen_server:call(ejabberd_odbc_sup:get_random_pid(),
+                   {sql_query, Query}, 60000).
 
 escape(S) ->
     [case C of
diff --git a/src/odbc/ejabberd_odbc_sup.erl b/src/odbc/ejabberd_odbc_sup.erl
new file mode 100644 (file)
index 0000000..4ca7ff3
--- /dev/null
@@ -0,0 +1,46 @@
+%%%----------------------------------------------------------------------
+%%% File    : ejabberd_odbc_sup.erl
+%%% Author  : Alexey Shchepin <alexey@sevcom.net>
+%%% Purpose : ODBC connections supervisor
+%%% Created : 22 Dec 2004 by Alexey Shchepin <alexey@sevcom.net>
+%%% Id      : $Id$
+%%%----------------------------------------------------------------------
+
+-module(ejabberd_odbc_sup).
+-author('alexey@sevcom.net').
+-vsn('$Revision$ ').
+
+-export([start_link/0,
+        init/1,
+        get_pids/0,
+        get_random_pid/0
+       ]).
+
+-include("ejabberd.hrl").
+
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+init(_) ->
+    % TODO
+    N = 10,
+    {ok, {{one_for_one, 10, 1},
+         lists:map(
+           fun(I) ->
+                   {I,
+                    {ejabberd_odbc, start_link, []},
+                    transient,
+                    brutal_kill,
+                    worker,
+                    [?MODULE]}
+           end, lists:seq(1, N))}}.
+
+get_pids() ->
+    [Child ||
+       {_Id, Child, _Type, _Modules} <- supervisor:which_children(?MODULE),
+       Child /= undefined].
+
+get_random_pid() ->
+    Pids = get_pids(),
+    lists:nth(erlang:phash(now(), length(Pids)), Pids).
+