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 VMware, Inc.
14
%% Copyright (c) 2007-2013 VMware, Inc. All rights reserved.
17
-module(rabbit_federation_old_link_sup).
19
-behaviour(supervisor2).
21
-include_lib("rabbit_common/include/rabbit.hrl").
22
-include("rabbit_federation_old.hrl").
24
%% Supervises the upstream links for an exchange.
26
-export([start_link/1]).
29
start_link(Args) -> supervisor2:start_link(?MODULE, Args).
31
%%----------------------------------------------------------------------------
33
init({UpstreamSet, XName}) ->
34
%% We can't look this up in fed_exchange or fed_sup since
35
%% mirrored_sup may fail us over to a different node with a
36
%% different definition of the same upstream-set. This is the
37
%% first point at which we know we're not switching nodes.
38
{ok, Upstreams} = rabbit_federation_old_upstream:from_set(UpstreamSet, XName),
39
%% 1, 1 so that the supervisor can give up and get into waiting
40
%% for the reconnect_delay quickly.
41
{ok, {{one_for_one, 1, 1},
42
[spec(Upstream, XName) || Upstream <- Upstreams]}}.
44
spec(Upstream = #upstream{reconnect_delay = Delay}, XName) ->
45
{Upstream, {rabbit_federation_old_link, start_link, [{Upstream, XName}]},
46
{permanent, Delay}, ?MAX_WAIT, worker,
47
[rabbit_federation_old_link]}.