]> review.fuel-infra Code Review - packages/trusty/rabbitmq-server.git/blob
239fcbf9f813c36dd927b4c01cbf5bbdf97078be
[packages/trusty/rabbitmq-server.git] /
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/
5 %%
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.
10 %%
11 %% The Original Code is RabbitMQ Federation.
12 %%
13 %% The Initial Developer of the Original Code is GoPivotal, Inc.
14 %% Copyright (c) 2007-2014 GoPivotal, Inc.  All rights reserved.
15 %%
16
17 -module(rabbit_federation_exchange_link_sup_sup).
18
19 -behaviour(mirrored_supervisor).
20
21 -include_lib("rabbit_common/include/rabbit.hrl").
22 -define(SUPERVISOR, ?MODULE).
23
24 %% Supervises the upstream links for all exchanges (but not queues). We need
25 %% different handling here since exchanges want a mirrored sup.
26
27 -export([start_link/0, start_child/1, adjust/1, stop_child/1]).
28 -export([init/1]).
29
30 %%----------------------------------------------------------------------------
31
32 start_link() ->
33     mirrored_supervisor:start_link({local, ?SUPERVISOR}, ?SUPERVISOR,
34                                    fun rabbit_misc:execute_mnesia_transaction/1,
35                                    ?MODULE, []).
36
37 %% Note that the next supervisor down, rabbit_federation_link_sup, is common
38 %% between exchanges and queues.
39 start_child(X) ->
40     case mirrored_supervisor:start_child(
41            ?SUPERVISOR,
42            {id(X), {rabbit_federation_link_sup, start_link, [X]},
43             transient, ?MAX_WAIT, supervisor,
44             [rabbit_federation_link_sup]}) of
45         {ok, _Pid}             -> ok;
46         %% A link returned {stop, gone}, the link_sup shut down, that's OK.
47         {error, {shutdown, _}} -> ok
48     end.
49
50 adjust(Reason) ->
51     [rabbit_federation_link_sup:adjust(Pid, X, Reason) ||
52         {X, Pid, _, _} <- mirrored_supervisor:which_children(?SUPERVISOR)],
53     ok.
54
55 stop_child(X) ->
56     ok = mirrored_supervisor:terminate_child(?SUPERVISOR, id(X)),
57     ok = mirrored_supervisor:delete_child(?SUPERVISOR, id(X)).
58
59 %%----------------------------------------------------------------------------
60
61 init([]) ->
62     {ok, {{one_for_one, 3, 10}, []}}.
63
64 %% See comment in rabbit_federation_queue_link_sup_sup:id/1
65 id(X = #exchange{}) -> X#exchange{scratches = none}.