1%% This Source Code Form is subject to the terms of the Mozilla Public
2%% License, v. 2.0. If a copy of the MPL was not distributed with this
3%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4%%
5%% Copyright (c) 2007-2021 VMware, Inc. or its affiliates.  All rights reserved.
6%%
7
8-module(rabbit_client_sup).
9
10-behaviour(supervisor2).
11
12-export([start_link/1, start_link/2, start_link_worker/2]).
13
14-export([init/1]).
15
16-include_lib("rabbit_common/include/rabbit.hrl").
17
18%%----------------------------------------------------------------------------
19
20-spec start_link(rabbit_types:mfargs()) ->
21          rabbit_types:ok_pid_or_error().
22
23start_link(Callback) ->
24    supervisor2:start_link(?MODULE, Callback).
25
26-spec start_link({'local', atom()}, rabbit_types:mfargs()) ->
27          rabbit_types:ok_pid_or_error().
28
29start_link(SupName, Callback) ->
30    supervisor2:start_link(SupName, ?MODULE, Callback).
31
32-spec start_link_worker({'local', atom()}, rabbit_types:mfargs()) ->
33          rabbit_types:ok_pid_or_error().
34
35start_link_worker(SupName, Callback) ->
36    supervisor2:start_link(SupName, ?MODULE, {Callback, worker}).
37
38init({M,F,A}) ->
39    {ok, {{simple_one_for_one, 0, 1},
40          [{client, {M,F,A}, temporary, infinity, supervisor, [M]}]}};
41init({{M,F,A}, worker}) ->
42    {ok, {{simple_one_for_one, 0, 1},
43          [{client, {M,F,A}, temporary, ?WORKER_WAIT, worker, [M]}]}}.
44