diff options
author | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-03-05 15:34:38 +0000 |
---|---|---|
committer | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-03-05 15:34:38 +0000 |
commit | f51479e4876b29ecbcfb7d633afc9df215cb8b8b (patch) | |
tree | 15e028cb1827687645a020712d59fa278be76285 /src | |
parent | c95a550b89724c255769d4fee2f8f9fababe7e75 (diff) | |
download | rabbitmq-server-f51479e4876b29ecbcfb7d633afc9df215cb8b8b.tar.gz |
-callbacks for gen_server2. USE_SPECS now requires R15B.
Diffstat (limited to 'src')
-rw-r--r-- | src/gen_server2.erl | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/src/gen_server2.erl b/src/gen_server2.erl index f8537487..765009ff 100644 --- a/src/gen_server2.erl +++ b/src/gen_server2.erl @@ -31,13 +31,13 @@ %% handle_pre_hibernate/1 then the default action is to hibernate. %% %% 6) init can return a 4th arg, {backoff, InitialTimeout, -%% MinimumTimeout, DesiredHibernatePeriod} (all in -%% milliseconds). Then, on all callbacks which can return a timeout -%% (including init), timeout can be 'hibernate'. When this is the -%% case, the current timeout value will be used (initially, the -%% InitialTimeout supplied from init). After this timeout has -%% occurred, hibernation will occur as normal. Upon awaking, a new -%% current timeout value will be calculated. +%% MinimumTimeout, DesiredHibernatePeriod} (all in milliseconds, +%% 'infinity' does not make sense here). Then, on all callbacks which +%% can return a timeout (including init), timeout can be +%% 'hibernate'. When this is the case, the current timeout value will +%% be used (initially, the InitialTimeout supplied from init). After +%% this timeout has occurred, hibernation will occur as normal. Upon +%% awaking, a new current timeout value will be calculated. %% %% The purpose is that the gen_server2 takes care of adjusting the %% current timeout value such that the process will increase the @@ -135,9 +135,10 @@ %%% Reason = normal | shutdown | Term, terminate(State) is called %%% %%% terminate(Reason, State) Let the user module clean up +%%% Reason = normal | shutdown | {shutdown, Term} | Term %%% always called when server terminates %%% -%%% ==> ok +%%% ==> ok | Term %%% %%% handle_pre_hibernate(State) %%% @@ -182,7 +183,9 @@ multi_call/2, multi_call/3, multi_call/4, enter_loop/3, enter_loop/4, enter_loop/5, enter_loop/6, wake_hib/1]). +-ifndef(use_specs). -export([behaviour_info/1]). +-endif. %% System exports -export([system_continue/3, @@ -220,12 +223,54 @@ %%% API %%%========================================================================= +-ifdef(use_specs). + +-type(millis() :: non_neg_integer()). + +-callback init(Args :: term()) -> + {ok, State :: term()} | + {ok, State :: term(), timeout() | hibernate} | + {ok, State :: term(), timeout() | hibernate, + {backoff, millis(), millis(), millis()}} | + ignore | + {stop, Reason :: term()}. +-callback handle_call(Request :: term(), From :: {pid(), Tag :: term()}, + State :: term()) -> + {reply, Reply :: term(), NewState :: term()} | + {reply, Reply :: term(), NewState :: term(), timeout() | hibernate} | + {noreply, NewState :: term()} | + {noreply, NewState :: term(), timeout() | hibernate} | + {stop, Reason :: term(), + Reply :: term(), NewState :: term()}. +-callback handle_cast(Request :: term(), State :: term()) -> + {noreply, NewState :: term()} | + {noreply, NewState :: term(), timeout() | hibernate} | + {stop, Reason :: term(), NewState :: term()}. +-callback handle_info(Info :: term(), State :: term()) -> + {noreply, NewState :: term()} | + {noreply, NewState :: term(), timeout() | hibernate} | + {stop, Reason :: term(), NewState :: term()}. +-callback terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()), + State :: term()) -> + (ok | term()). +-callback code_change(OldVsn :: (term() | {down, term()}), State :: term(), + Extra :: term()) -> + {ok, NewState :: term()} | {error, Reason :: term()}. + +%% It's not possible to define "optional" -callbacks, so putting specs +%% for handle_pre_hibernate/1 and handle_post_hibernate/1 will result +%% in warnings (the same applied for the behaviour_info before). + +-else. + behaviour_info(callbacks) -> [{init,1},{handle_call,3},{handle_cast,2},{handle_info,2}, {terminate,2},{code_change,3}]; behaviour_info(_Other) -> undefined. +-endif. + %%% ----------------------------------------------------------------- %%% Starts a generic server. %%% start(Mod, Args, Options) |