|
matthew@6072
|
1 |
%% The contents of this file are subject to the Mozilla Public License
|
|
matthew@6072
|
2 |
%% Version 1.1 (the "License"); you may not use this file except in
|
|
matthew@6072
|
3 |
%% compliance with the License. You may obtain a copy of the License
|
|
matthew@6072
|
4 |
%% at http://www.mozilla.org/MPL/
|
|
matthew@2926
|
5 |
%%
|
|
matthew@6072
|
6 |
%% Software distributed under the License is distributed on an "AS IS"
|
|
matthew@6072
|
7 |
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
matthew@6072
|
8 |
%% the License for the specific language governing rights and
|
|
matthew@6072
|
9 |
%% limitations under the License.
|
|
matthew@2926
|
10 |
%%
|
|
matthew@6072
|
11 |
%% The Original Code is RabbitMQ.
|
|
matthew@2926
|
12 |
%%
|
|
matthew@6072
|
13 |
%% The Initial Developer of the Original Code is VMware, Inc.
|
|
emile@8906
|
14 |
%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved.
|
|
matthew@2926
|
15 |
%%
|
|
matthew@2926
|
16 |
|
|
matthew@2926
|
17 |
-module(worker_pool_sup).
|
|
matthew@2926
|
18 |
|
|
matthew@2926
|
19 |
-behaviour(supervisor).
|
|
matthew@2926
|
20 |
|
|
matthew@2926
|
21 |
-export([start_link/0, start_link/1]).
|
|
matthew@2926
|
22 |
|
|
matthew@2926
|
23 |
-export([init/1]).
|
|
matthew@2926
|
24 |
|
|
matthew@2926
|
25 |
%%----------------------------------------------------------------------------
|
|
matthew@2926
|
26 |
|
|
matthew@2926
|
27 |
-ifdef(use_specs).
|
|
matthew@2926
|
28 |
|
|
alexandru@7795
|
29 |
-spec(start_link/0 :: () -> rabbit_types:ok_pid_or_error()).
|
|
alexandru@7795
|
30 |
-spec(start_link/1 :: (non_neg_integer()) -> rabbit_types:ok_pid_or_error()).
|
|
matthew@2926
|
31 |
|
|
matthew@2926
|
32 |
-endif.
|
|
matthew@2926
|
33 |
|
|
matthew@2926
|
34 |
%%----------------------------------------------------------------------------
|
|
matthew@2926
|
35 |
|
|
matthew@2926
|
36 |
-define(SERVER, ?MODULE).
|
|
matthew@2926
|
37 |
|
|
matthew@2926
|
38 |
%%----------------------------------------------------------------------------
|
|
matthew@2926
|
39 |
|
|
matthew@2926
|
40 |
start_link() ->
|
|
matthew@2926
|
41 |
start_link(erlang:system_info(schedulers)).
|
|
matthew@2926
|
42 |
|
|
matthew@2926
|
43 |
start_link(WCount) ->
|
|
matthew@2926
|
44 |
supervisor:start_link({local, ?SERVER}, ?MODULE, [WCount]).
|
|
matthew@2926
|
45 |
|
|
matthew@2926
|
46 |
%%----------------------------------------------------------------------------
|
|
matthew@2926
|
47 |
|
|
matthew@2926
|
48 |
init([WCount]) ->
|
|
matthew@2926
|
49 |
{ok, {{one_for_one, 10, 10},
|
|
matthew@2926
|
50 |
[{worker_pool, {worker_pool, start_link, []}, transient,
|
|
matthew@2926
|
51 |
16#ffffffff, worker, [worker_pool]} |
|
|
matthew@2926
|
52 |
[{N, {worker_pool_worker, start_link, [N]}, transient, 16#ffffffff,
|
|
matthew@2926
|
53 |
worker, [worker_pool_worker]} || N <- lists:seq(1, WCount)]]}}.
|