src/worker_pool_sup.erl
author Simon MacMullen <simon@rabbitmq.com>
Tue, 29 Jul 2014 11:02:51 +0100
changeset 13742 a712e0081c24
parent 13173 85a4d72b2d8e
permissions -rw-r--r--
stable to default
     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.
    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(worker_pool_sup).
    18 
    19 -behaviour(supervisor).
    20 
    21 -export([start_link/0, start_link/1]).
    22 
    23 -export([init/1]).
    24 
    25 %%----------------------------------------------------------------------------
    26 
    27 -ifdef(use_specs).
    28 
    29 -spec(start_link/0 :: () -> rabbit_types:ok_pid_or_error()).
    30 -spec(start_link/1 :: (non_neg_integer()) -> rabbit_types:ok_pid_or_error()).
    31 
    32 -endif.
    33 
    34 %%----------------------------------------------------------------------------
    35 
    36 -define(SERVER, ?MODULE).
    37 
    38 %%----------------------------------------------------------------------------
    39 
    40 start_link() ->
    41     start_link(erlang:system_info(schedulers)).
    42 
    43 start_link(WCount) ->
    44     supervisor:start_link({local, ?SERVER}, ?MODULE, [WCount]).
    45 
    46 %%----------------------------------------------------------------------------
    47 
    48 init([WCount]) ->
    49     {ok, {{one_for_one, 10, 10},
    50           [{worker_pool, {worker_pool, start_link, []}, transient,
    51             16#ffffffff, worker, [worker_pool]} |
    52            [{N, {worker_pool_worker, start_link, []}, transient, 16#ffffffff,
    53              worker, [worker_pool_worker]} || N <- lists:seq(1, WCount)]]}}.