aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2012-02-09 14:38:16 -0500
committerBrian Cully <bjc@kublai.com>2012-02-09 14:38:54 -0500
commitba58faaa776b911c3ce74e49cf39a9f14bc436d1 (patch)
treefd91fb11d387226228ce4d18dd54528a73ab3216 /src
parent8cd5a7f161743d6b6a995b92b1702909809b8cdc (diff)
downloadmysqlerl-ba58faaa776b911c3ce74e49cf39a9f14bc436d1.tar.gz
mysqlerl-ba58faaa776b911c3ce74e49cf39a9f14bc436d1.zip
Move functions from mysqlerl_sup to mysqlerl, and get rid of random_child/0.
Diffstat (limited to 'src')
-rw-r--r--src/mysqlerl.erl3
-rw-r--r--src/mysqlerl_app.erl4
-rw-r--r--src/mysqlerl_sup.erl26
3 files changed, 9 insertions, 24 deletions
diff --git a/src/mysqlerl.erl b/src/mysqlerl.erl
index 0b7d383..3aec2e5 100644
--- a/src/mysqlerl.erl
+++ b/src/mysqlerl.erl
@@ -65,7 +65,8 @@ commit(Ref, rollback, Timeout) ->
%% {ok, Ref} | {error, Reason}
%% Ref = connection_reference()
connect(Host, Port, Database, User, Password, Options) ->
- mysqlerl_sup:connect(Host, Port, Database, User, Password, Options).
+ supervisor:start_child(mysqlerl_sup, [self(), Host, Port, Database,
+ User, Password, Options]).
%% Arguments:
%% Ref = connection_reference()
diff --git a/src/mysqlerl_app.erl b/src/mysqlerl_app.erl
index a37e020..78aa202 100644
--- a/src/mysqlerl_app.erl
+++ b/src/mysqlerl_app.erl
@@ -6,8 +6,8 @@
%% Behavior callbacks.
-export([start/2, stop/1]).
-start(normal, []) ->
- mysqlerl_sup:start_link().
+start(normal, Name) ->
+ supervisor:start_link({local, mysqlerl_sup}, mysqlerl_sup, [Name]).
stop([]) ->
ok.
diff --git a/src/mysqlerl_sup.erl b/src/mysqlerl_sup.erl
index 361fe2b..9a3c4e8 100644
--- a/src/mysqlerl_sup.erl
+++ b/src/mysqlerl_sup.erl
@@ -3,25 +3,9 @@
-behavior(supervisor).
--export([start_link/0, init/1, connect/6, random_child/0]).
+-export([init/1]).
-start_link() ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-connect(Host, Port, Database, User, Password, Options) ->
- supervisor:start_child(?MODULE, [self(), Host, Port, Database,
- User, Password, Options]).
-
-random_child() ->
- case get_pids() of
- [] -> {error, no_connections};
- Pids -> lists:nth(erlang:phash(now(), length(Pids)), Pids)
- end.
-
-init([]) ->
- Connection = {undefined, {mysqlerl_connection, start_link, []},
- transient, 5, worker, [mysqlerl_connection]},
- {ok, {{simple_one_for_one, 10, 5}, [Connection]}}.
-
-get_pids() ->
- [Pid || {_Id, Pid, _Type, _Modules} <- supervisor:which_children(?MODULE)].
+init([Name]) ->
+ Connection = {Name, {mysqlerl_connection, start_link, []},
+ temporary, 7000, worker, [mysqlerl_connection]},
+ {ok, {{simple_one_for_one, 0, 3600}, [Connection]}}.