diff options
author | Alexey Shchepin <alexey@process-one.net> | 2004-12-29 23:10:14 +0000 |
---|---|---|
committer | Alexey Shchepin <alexey@process-one.net> | 2004-12-29 23:10:14 +0000 |
commit | 3416cbe63ae9954e0b3942620aee1afa5cc8b9ab (patch) | |
tree | c6dcda449a3baeb4dd82d1a76d5d07bd58f9713a /src/odbc | |
parent | * src/mod_roster_odbc.erl: Roster support via ODBC (not completed) (diff) |
* 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)
SVN Revision: 295
Diffstat (limited to 'src/odbc')
-rw-r--r-- | src/odbc/ejabberd_odbc.erl | 7 | ||||
-rw-r--r-- | src/odbc/ejabberd_odbc_sup.erl | 46 |
2 files changed, 50 insertions, 3 deletions
diff --git a/src/odbc/ejabberd_odbc.erl b/src/odbc/ejabberd_odbc.erl index c496bf2be..3800d141e 100644 --- a/src/odbc/ejabberd_odbc.erl +++ b/src/odbc/ejabberd_odbc.erl @@ -31,13 +31,14 @@ %%% 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 index 000000000..4ca7ff303 --- /dev/null +++ b/src/odbc/ejabberd_odbc_sup.erl @@ -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). + |