1 %% The contents of this file are subject to the Mozilla Public License
2 %% Version 1.1 (the "License"); you may not use this file except in
3 %% compliance with the License. You may obtain a copy of the License
4 %% at http://www.mozilla.org/MPL/
6 %% Software distributed under the License is distributed on an "AS IS"
7 %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8 %% the License for the specific language governing rights and
9 %% limitations under the License.
11 %% The Original Code is RabbitMQ Federation.
13 %% The Initial Developer of the Original Code is GoPivotal, Inc.
14 %% Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
17 -module(rabbit_federation_exchange_link_sup_sup).
19 -behaviour(mirrored_supervisor).
21 -include_lib("rabbit_common/include/rabbit.hrl").
22 -define(SUPERVISOR, ?MODULE).
24 %% Supervises the upstream links for all exchanges (but not queues). We need
25 %% different handling here since exchanges want a mirrored sup.
27 -export([start_link/0, start_child/1, adjust/1, stop_child/1]).
30 %%----------------------------------------------------------------------------
33 mirrored_supervisor:start_link({local, ?SUPERVISOR}, ?SUPERVISOR,
34 fun rabbit_misc:execute_mnesia_transaction/1,
37 %% Note that the next supervisor down, rabbit_federation_link_sup, is common
38 %% between exchanges and queues.
40 case mirrored_supervisor:start_child(
42 {id(X), {rabbit_federation_link_sup, start_link, [X]},
43 transient, ?MAX_WAIT, supervisor,
44 [rabbit_federation_link_sup]}) of
46 %% A link returned {stop, gone}, the link_sup shut down, that's OK.
47 {error, {shutdown, _}} -> ok
51 [rabbit_federation_link_sup:adjust(Pid, X, Reason) ||
52 {X, Pid, _, _} <- mirrored_supervisor:which_children(?SUPERVISOR)],
56 ok = mirrored_supervisor:terminate_child(?SUPERVISOR, id(X)),
57 ok = mirrored_supervisor:delete_child(?SUPERVISOR, id(X)).
59 %%----------------------------------------------------------------------------
62 {ok, {{one_for_one, 3, 10}, []}}.
64 %% See comment in rabbit_federation_queue_link_sup_sup:id/1
65 id(X = #exchange{}) -> X#exchange{scratches = none}.