diff options
author | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-04-02 16:37:08 +0100 |
---|---|---|
committer | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-04-02 16:37:08 +0100 |
commit | d5dc852a048f0a52227e87c2bc0ea28eee1d2b56 (patch) | |
tree | 24d9c5c330b1238dc0ec2fa6126aaec5d3e88dd0 | |
parent | 8782eb25a81a979bf5cc41c86e6500ceda2a57ae (diff) | |
download | rabbitmq-server-d5dc852a048f0a52227e87c2bc0ea28eee1d2b56.tar.gz |
Added callback info to supervisor2.
-rw-r--r-- | src/mirrored_supervisor.erl | 51 | ||||
-rw-r--r-- | src/supervisor2.erl | 135 |
2 files changed, 136 insertions, 50 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl index a599effa..9c814bd7 100644 --- a/src/mirrored_supervisor.erl +++ b/src/mirrored_supervisor.erl @@ -142,16 +142,6 @@ -ifdef(use_specs). --type child() :: pid() | 'undefined'. --type child_id() :: term(). --type modules() :: [module()] | 'dynamic'. --type worker() :: 'worker' | 'supervisor'. --type sup_name() :: {'local', Name :: atom()} | {'global', Name :: atom()}. --type sup_ref() :: (Name :: atom()) - | {Name :: atom(), Node :: node()} - | {'global', Name :: atom()} - | pid(). - -type startlink_err() :: {'already_started', pid()} | 'shutdown' | term(). -type startlink_ret() :: {'ok', pid()} | 'ignore' | {'error', startlink_err()}. @@ -163,50 +153,15 @@ Args :: term(). -spec start_link(SupName, GroupName, Module, Args) -> startlink_ret() when - SupName :: sup_name(), + SupName :: supervisor2:sup_name(), GroupName :: group_name(), Module :: module(), Args :: term(). --spec start_child(SupRef, ChildSpec) -> supervisor:startchild_ret() when - SupRef :: sup_ref(), - ChildSpec :: supervisor:child_spec() | (List :: [term()]). - --spec restart_child(SupRef, Id) -> Result when - SupRef :: sup_ref(), - Id :: child_id(), - Result :: {'ok', Child :: child()} - | {'ok', Child :: child(), Info :: term()} - | {'error', Error}, - Error :: 'running' | 'not_found' | 'simple_one_for_one' | term(). - --spec delete_child(SupRef, Id) -> Result when - SupRef :: sup_ref(), - Id :: child_id(), - Result :: 'ok' | {'error', Error}, - Error :: 'running' | 'not_found' | 'simple_one_for_one'. - --spec terminate_child(SupRef, Id) -> Result when - SupRef :: sup_ref(), - Id :: pid() | child_id(), - Result :: 'ok' | {'error', Error}, - Error :: 'not_found' | 'simple_one_for_one'. - --spec which_children(SupRef) -> [{Id,Child,Type,Modules}] when - SupRef :: sup_ref(), - Id :: child_id() | 'undefined', - Child :: child(), - Type :: worker(), - Modules :: modules(). - --spec check_childspecs(ChildSpecs) -> Result when - ChildSpecs :: [supervisor:child_spec()], - Result :: 'ok' | {'error', Error :: term()}. - -spec start_internal(Group, ChildSpecs) -> Result when Group :: group_name(), - ChildSpecs :: [supervisor:child_spec()], - Result :: startlink_ret(). + ChildSpecs :: [supervisor2:child_spec()], + Result :: supervisor2:startlink_ret(). -spec create_tables() -> Result when Result :: 'ok'. diff --git a/src/supervisor2.erl b/src/supervisor2.erl index 8dd8aba8..f1b74878 100644 --- a/src/supervisor2.erl +++ b/src/supervisor2.erl @@ -81,8 +81,6 @@ which_children/1, find_child/2, check_childspecs/1]). --export([behaviour_info/1]). - %% Internal exports -export([init/1, handle_call/3, handle_info/2, terminate/2, code_change/3]). -export([handle_cast/2]). @@ -112,11 +110,144 @@ -define(is_terminate_simple(State), State#state.strategy =:= simple_one_for_one_terminate). +-ifdef(use_specs). + +%%-------------------------------------------------------------------------- +%% Types +%%-------------------------------------------------------------------------- + +-export_type([child_spec/0, startchild_ret/0, strategy/0, sup_name/0]). + +-type child() :: 'undefined' | pid(). +-type child_id() :: term(). +-type mfargs() :: {M :: module(), F :: atom(), A :: [term()] | undefined}. +-type modules() :: [module()] | 'dynamic'. +-type delay() :: non_neg_integer(). +-type restart() :: 'permanent' | 'transient' | 'temporary' | 'intrinsic' + | {'permanent', delay()} | {'transient', delay()} + | {'intrinsic', delay()}. +-type shutdown() :: 'brutal_kill' | timeout(). +-type worker() :: 'worker' | 'supervisor'. +-type sup_name() :: {'local', Name :: atom()} | {'global', Name :: atom()}. +-type sup_ref() :: (Name :: atom()) + | {Name :: atom(), Node :: node()} + | {'global', Name :: atom()} + | pid(). +-type child_spec() :: {Id :: child_id(), + StartFunc :: mfargs(), + Restart :: restart(), + Shutdown :: shutdown(), + Type :: worker(), + Modules :: modules()}. + + +-type strategy() :: 'one_for_all' | 'one_for_one' + | 'rest_for_one' | 'simple_one_for_one' + | 'simple_one_for_one_terminate'. + +-type child_rec() :: #child{pid :: child() | {restarting,pid()} | [pid()], + name :: child_id(), + mfa :: mfargs(), + restart_type :: restart(), + shutdown :: shutdown(), + child_type :: worker(), + modules :: modules()}. + +-type state() :: #state{strategy :: strategy(), + children :: [child_rec()], + dynamics :: ?DICT(), + intensity :: non_neg_integer(), + period :: pos_integer()}. + +%%-------------------------------------------------------------------------- +%% Callback behaviour +%%-------------------------------------------------------------------------- + +-callback init(Args :: term()) -> + {ok, {{RestartStrategy :: strategy(), + MaxR :: non_neg_integer(), + MaxT :: non_neg_integer()}, + [ChildSpec :: child_spec()]}} + | ignore. + +%%-------------------------------------------------------------------------- +%% Specs +%%-------------------------------------------------------------------------- + +-type startchild_err() :: 'already_present' + | {'already_started', Child :: child()} | term(). +-type startchild_ret() :: {'ok', Child :: child()} + | {'ok', Child :: child(), Info :: term()} + | {'error', startchild_err()}. + +-spec start_child(SupRef, ChildSpec) -> startchild_ret() when + SupRef :: sup_ref(), + ChildSpec :: child_spec() | (List :: [term()]). + +-spec restart_child(SupRef, Id) -> Result when + SupRef :: sup_ref(), + Id :: child_id(), + Result :: {'ok', Child :: child()} + | {'ok', Child :: child(), Info :: term()} + | {'error', Error}, + Error :: 'running' | 'not_found' | 'simple_one_for_one' | term(). + +-spec delete_child(SupRef, Id) -> Result when + SupRef :: sup_ref(), + Id :: child_id(), + Result :: 'ok' | {'error', Error}, + Error :: 'running' | 'not_found' | 'simple_one_for_one'. + +-spec terminate_child(SupRef, Id) -> Result when + SupRef :: sup_ref(), + Id :: pid() | child_id(), + Result :: 'ok' | {'error', Error}, + Error :: 'not_found' | 'simple_one_for_one'. + +-spec which_children(SupRef) -> [{Id,Child,Type,Modules}] when + SupRef :: sup_ref(), + Id :: child_id() | 'undefined', + Child :: child(), + Type :: worker(), + Modules :: modules(). + +-spec check_childspecs(ChildSpecs) -> Result when + ChildSpecs :: [child_spec()], + Result :: 'ok' | {'error', Error :: term()}. + +-type init_sup_name() :: sup_name() | 'self'. + +-type stop_rsn() :: 'shutdown' | {'bad_return', {module(),'init', term()}} + | {'bad_start_spec', term()} | {'start_spec', term()} + | {'supervisor_data', term()}. + +-spec init({init_sup_name(), module(), [term()]}) -> + {'ok', state()} | 'ignore' | {'stop', stop_rsn()}. + +-type call() :: 'which_children'. +-spec handle_call(call(), term(), state()) -> {'reply', term(), state()}. + +-spec handle_cast('null', state()) -> {'noreply', state()}. + +-spec handle_info(term(), state()) -> + {'noreply', state()} | {'stop', 'shutdown', state()}. + +-spec terminate(term(), state()) -> 'ok'. + +-spec code_change(term(), state(), term()) -> + {'ok', state()} | {'error', term()}. + +-else. + +-export([behaviour_info/1]). + behaviour_info(callbacks) -> [{init,1}]; behaviour_info(_Other) -> undefined. +-endif. + %%% --------------------------------------------------- %%% This is a general process supervisor built upon gen_server.erl. %%% Servers/processes should/could also be built using gen_server.erl. |