diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2010-07-21 19:10:41 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2010-07-21 19:10:41 +0100 |
| commit | 84ca7ad4736289a4a93af33378a05c19c775cfa7 (patch) | |
| tree | e6cae31d84a68a2d4aeb7699b4f2821b1aedfae5 /src | |
| parent | 9fb229328b35ba8952e185865ce37f11cd826f4f (diff) | |
| parent | ddd7eb9d66921dcf99a793719799d22bf4bb9f5c (diff) | |
| download | rabbitmq-server-git-84ca7ad4736289a4a93af33378a05c19c775cfa7.tar.gz | |
Merged default into bug21387
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_access_control.erl | 10 | ||||
| -rw-r--r-- | src/rabbit_amqqueue.erl | 11 | ||||
| -rw-r--r-- | src/rabbit_amqqueue_process.erl | 6 | ||||
| -rw-r--r-- | src/rabbit_backing_queue.erl | 20 | ||||
| -rw-r--r-- | src/rabbit_dialyzer.erl | 4 | ||||
| -rw-r--r-- | src/rabbit_exchange.erl | 1 | ||||
| -rw-r--r-- | src/rabbit_exchange_type_topic.erl | 3 | ||||
| -rw-r--r-- | src/rabbit_invariable_queue.erl | 13 | ||||
| -rw-r--r-- | src/rabbit_misc.erl | 2 | ||||
| -rw-r--r-- | src/rabbit_multi.erl | 6 | ||||
| -rw-r--r-- | src/rabbit_sup.erl | 8 | ||||
| -rw-r--r-- | src/rabbit_tests.erl | 2 |
12 files changed, 52 insertions, 34 deletions
diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl index 30bae25e5a..3aaf59281e 100644 --- a/src/rabbit_access_control.erl +++ b/src/rabbit_access_control.erl @@ -177,11 +177,9 @@ check_resource_access(Username, <<"">> -> <<$^, $$>>; RE -> RE end, - case regexp:match( - binary_to_list(Name), - binary_to_list(PermRegexp)) of - {match, _, _} -> true; - nomatch -> false + case re:run(Name, PermRegexp, [{capture, none}]) of + match -> true; + nomatch -> false end end, if Res -> ok; @@ -306,7 +304,7 @@ list_vhosts() -> validate_regexp(RegexpBin) -> Regexp = binary_to_list(RegexpBin), - case regexp:parse(Regexp) of + case re:compile(Regexp) of {ok, _} -> ok; {error, Reason} -> throw({error, {invalid_regexp, Regexp, Reason}}) end. diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 2c5465e690..0489f13961 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -31,7 +31,7 @@ -module(rabbit_amqqueue). --export([start/0, declare/5, delete/3, purge/1]). +-export([start/0, stop/0, declare/5, delete/3, purge/1]). -export([internal_declare/2, internal_delete/1, maybe_run_queue_via_backing_queue/2, update_ram_duration/1, set_ram_duration_target/2, @@ -72,6 +72,7 @@ 'ok' | {'error', [{'error' | 'exit' | 'throw', any()}]}). -spec(start/0 :: () -> 'ok'). +-spec(stop/0 :: () -> 'ok'). -spec(declare/5 :: (name(), boolean(), boolean(), rabbit_framing:amqp_table(), rabbit_types:maybe(pid())) @@ -156,7 +157,7 @@ start() -> DurableQueues = find_durable_queues(), - {ok, BQ} = application:get_env(backing_queue_module), + {ok, BQ} = application:get_env(rabbit, backing_queue_module), ok = BQ:start([QName || #amqqueue{name = QName} <- DurableQueues]), {ok,_} = supervisor:start_child( rabbit_sup, @@ -166,6 +167,12 @@ start() -> _RealDurableQueues = recover_durable_queues(DurableQueues), ok. +stop() -> + ok = supervisor:terminate_child(rabbit_sup, rabbit_amqqueue_sup), + ok = supervisor:delete_child(rabbit_sup, rabbit_amqqueue_sup), + {ok, BQ} = application:get_env(rabbit, backing_queue_module), + ok = BQ:stop(). + find_durable_queues() -> Node = node(), %% TODO: use dirty ops instead diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl index e7d4817dee..c099c0510d 100644 --- a/src/rabbit_amqqueue_process.erl +++ b/src/rabbit_amqqueue_process.erl @@ -192,7 +192,7 @@ next_state(State) -> State1 = #q{backing_queue = BQ, backing_queue_state = BQS} = ensure_rate_timer(State), State2 = ensure_stats_timer(State1), - case BQ:needs_sync(BQS)of + case BQ:needs_idle_timeout(BQS)of true -> {ensure_sync_timer(State2), 0}; false -> {stop_sync_timer(State2), hibernate} end. @@ -201,7 +201,7 @@ ensure_sync_timer(State = #q{sync_timer_ref = undefined, backing_queue = BQ}) -> {ok, TRef} = timer:apply_after( ?SYNC_INTERVAL, rabbit_amqqueue, maybe_run_queue_via_backing_queue, - [self(), fun (BQS) -> BQ:sync(BQS) end]), + [self(), fun (BQS) -> BQ:idle_timeout(BQS) end]), State#q{sync_timer_ref = TRef}; ensure_sync_timer(State) -> State. @@ -860,7 +860,7 @@ handle_info({'DOWN', _MonitorRef, process, DownPid, _Reason}, State) -> handle_info(timeout, State = #q{backing_queue = BQ}) -> noreply(maybe_run_queue_via_backing_queue( - fun (BQS) -> BQ:sync(BQS) end, State)); + fun (BQS) -> BQ:idle_timeout(BQS) end, State)); handle_info({'EXIT', _Pid, Reason}, State) -> {stop, Reason, State}; diff --git a/src/rabbit_backing_queue.erl b/src/rabbit_backing_queue.erl index 432d62900b..2230c507e9 100644 --- a/src/rabbit_backing_queue.erl +++ b/src/rabbit_backing_queue.erl @@ -42,6 +42,11 @@ behaviour_info(callbacks) -> %% shared resources. {start, 1}, + %% Called to tear down any state/resources. NB: Implementations + %% should not depend on this function being called on shutdown + %% and instead should hook into the rabbit supervision hierarchy. + {stop, 0}, + %% Initialise the backing queue and its state. {init, 3}, @@ -113,14 +118,15 @@ behaviour_info(callbacks) -> %% queue. {ram_duration, 1}, - %% Should 'sync' be called as soon as the queue process can - %% manage (either on an empty mailbox, or when a timer fires)? - {needs_sync, 1}, + %% Should 'idle_timeout' be called as soon as the queue process + %% can manage (either on an empty mailbox, or when a timer + %% fires)? + {needs_idle_timeout, 1}, - %% Called (eventually) after needs_sync returns 'true'. Note this - %% may be called more than once for each 'true' returned from - %% needs_sync. - {sync, 1}, + %% Called (eventually) after needs_idle_timeout returns + %% 'true'. Note this may be called more than once for each 'true' + %% returned from needs_idle_timeout. + {idle_timeout, 1}, %% Called immediately before the queue hibernates. {handle_pre_hibernate, 1}, diff --git a/src/rabbit_dialyzer.erl b/src/rabbit_dialyzer.erl index 0ec6beb676..51bd6b1f93 100644 --- a/src/rabbit_dialyzer.erl +++ b/src/rabbit_dialyzer.erl @@ -56,7 +56,7 @@ create_basic_plt(BasicPltPath) -> ok. add_to_plt(PltPath, FilesString) -> - {ok, Files} = regexp:split(FilesString, " "), + Files = string:tokens(FilesString, " "), DialyzerWarnings = dialyzer:run([{analysis_type, plt_add}, {init_plt, PltPath}, {output_plt, PltPath}, @@ -65,7 +65,7 @@ add_to_plt(PltPath, FilesString) -> ok. dialyze_files(PltPath, ModifiedFiles) -> - {ok, Files} = regexp:split(ModifiedFiles, " "), + Files = string:tokens(ModifiedFiles, " "), DialyzerWarnings = dialyzer:run([{init_plt, PltPath}, {files, Files}]), case DialyzerWarnings of diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 67eaf8e691..1b9ec06732 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -49,7 +49,6 @@ -import(mnesia). -import(sets). -import(lists). --import(regexp). %%---------------------------------------------------------------------------- diff --git a/src/rabbit_exchange_type_topic.erl b/src/rabbit_exchange_type_topic.erl index a374cfee7f..89b2441e38 100644 --- a/src/rabbit_exchange_type_topic.erl +++ b/src/rabbit_exchange_type_topic.erl @@ -67,8 +67,7 @@ publish(#exchange{name = Name}, Delivery = Delivery). split_topic_key(Key) -> - {ok, KeySplit} = regexp:split(binary_to_list(Key), "\\."), - KeySplit. + re:split(Key, "\\.", [{return, list}]). topic_matches(PatternKey, RoutingKey) -> P = split_topic_key(PatternKey), diff --git a/src/rabbit_invariable_queue.erl b/src/rabbit_invariable_queue.erl index 8214b976c4..4e0dad8422 100644 --- a/src/rabbit_invariable_queue.erl +++ b/src/rabbit_invariable_queue.erl @@ -34,10 +34,10 @@ -export([init/3, terminate/1, delete_and_terminate/1, purge/1, publish/2, publish_delivered/3, fetch/2, ack/2, tx_publish/3, tx_ack/3, tx_rollback/2, tx_commit/3, requeue/2, len/1, is_empty/1, - set_ram_duration_target/2, ram_duration/1, needs_sync/1, sync/1, - handle_pre_hibernate/1, status/1]). + set_ram_duration_target/2, ram_duration/1, needs_idle_timeout/1, + idle_timeout/1, handle_pre_hibernate/1, status/1]). --export([start/1]). +-export([start/1, stop/0]). -behaviour(rabbit_backing_queue). @@ -61,6 +61,9 @@ start(DurableQueues) -> ok = rabbit_sup:start_child(rabbit_persister, [DurableQueues]). +stop() -> + ok = rabbit_sup:stop_child(rabbit_persister). + init(QName, IsDurable, Recover) -> Q = queue:from_list(case IsDurable andalso Recover of true -> rabbit_persister:queue_content(QName); @@ -197,9 +200,9 @@ set_ram_duration_target(_DurationTarget, State) -> State. ram_duration(State) -> {0, State}. -needs_sync(_State) -> false. +needs_idle_timeout(_State) -> false. -sync(State) -> State. +idle_timeout(State) -> State. handle_pre_hibernate(State) -> State. diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index fcc9fc7e54..9ed106d6fa 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -585,7 +585,7 @@ string_to_pid(Str) -> binary_to_term(<<131,103,NodeEnc/binary,Id:32,Ser:32,0:8>>); nomatch -> throw(Err) - end. + end. version_compare(A, B, lte) -> case version_compare(A, B) of diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 5db1d77a32..3facef17f7 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -309,9 +309,9 @@ is_dead(Pid) -> {win32, fun () -> Res = os:cmd("tasklist /nh /fi \"pid eq " ++ PidS ++ "\""), - case regexp:first_match(Res, "erl.exe") of - {match, _, _} -> false; - _ -> true + case re:run(Res, "erl\\.exe", [{capture, none}]) of + match -> false; + _ -> true end end}]). diff --git a/src/rabbit_sup.erl b/src/rabbit_sup.erl index 2c5e51125e..97613d17a5 100644 --- a/src/rabbit_sup.erl +++ b/src/rabbit_sup.erl @@ -34,7 +34,7 @@ -behaviour(supervisor). -export([start_link/0, start_child/1, start_child/2, start_child/3, - start_restartable_child/1, start_restartable_child/2]). + start_restartable_child/1, start_restartable_child/2, stop_child/1]). -export([init/1]). @@ -69,5 +69,11 @@ start_restartable_child(Mod, Args) -> transient, infinity, supervisor, [rabbit_restartable_sup]}), ok. +stop_child(ChildId) -> + case supervisor:terminate_child(?SERVER, ChildId) of + ok -> supervisor:delete_child(?SERVER, ChildId); + E -> E + end. + init([]) -> {ok, {{one_for_all, 0, 1}, []}}. diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index ff7c07e37e..de06c048a2 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -1183,6 +1183,6 @@ handle_hook(HookName, Handler, Args) -> A = atom_to_list(HookName) ++ "_" ++ atom_to_list(Handler) ++ "_fired", put(list_to_atom(A), Args). bad_handle_hook(_, _, _) -> - bad:bad(). + exit(bad_handle_hook_called). extra_arg_hook(Hookname, Handler, Args, Extra1, Extra2) -> handle_hook(Hookname, Handler, {Args, Extra1, Extra2}). |
