diff options
Diffstat (limited to 'deps/rabbit_common/src')
40 files changed, 861 insertions, 1241 deletions
diff --git a/deps/rabbit_common/src/app_utils.erl b/deps/rabbit_common/src/app_utils.erl index 748f285af9..6504c3f543 100644 --- a/deps/rabbit_common/src/app_utils.erl +++ b/deps/rabbit_common/src/app_utils.erl @@ -19,8 +19,6 @@ stop_applications/1, stop_applications/2, app_dependency_order/2, app_dependencies/1]). --ifdef(use_specs). - -type error_handler() :: fun((atom(), any()) -> 'ok'). -spec load_applications([atom()]) -> 'ok'. @@ -31,8 +29,6 @@ -spec app_dependency_order([atom()], boolean()) -> [digraph:vertex()]. -spec app_dependencies(atom()) -> [atom()]. --endif. - %%--------------------------------------------------------------------------- %% Public API diff --git a/deps/rabbit_common/src/credit_flow.erl b/deps/rabbit_common/src/credit_flow.erl index 029c55fbc9..0fe3e66664 100644 --- a/deps/rabbit_common/src/credit_flow.erl +++ b/deps/rabbit_common/src/credit_flow.erl @@ -65,22 +65,19 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([bump_msg/0]). -opaque(bump_msg() :: {pid(), non_neg_integer()}). -type(credit_spec() :: {non_neg_integer(), non_neg_integer()}). --spec(send/1 :: (pid()) -> 'ok'). --spec(send/2 :: (pid(), credit_spec()) -> 'ok'). --spec(ack/1 :: (pid()) -> 'ok'). --spec(ack/2 :: (pid(), credit_spec()) -> 'ok'). --spec(handle_bump_msg/1 :: (bump_msg()) -> 'ok'). --spec(blocked/0 :: () -> boolean()). --spec(peer_down/1 :: (pid()) -> 'ok'). - --endif. +-spec send + (pid()) -> 'ok'; + (credit_spec()) -> 'ok'. +-spec ack(pid()) -> 'ok'. +-spec ack(pid(), credit_spec()) -> 'ok'. +-spec handle_bump_msg(bump_msg()) -> 'ok'. +-spec blocked() -> boolean(). +-spec peer_down(pid()) -> 'ok'. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/gen_server2.erl b/deps/rabbit_common/src/gen_server2.erl index 23494399d2..dc037592f5 100644 --- a/deps/rabbit_common/src/gen_server2.erl +++ b/deps/rabbit_common/src/gen_server2.erl @@ -220,21 +220,18 @@ -record(gs2_state, {parent, name, state, mod, time, timeout_state, queue, debug, prioritisers}). --ifdef(use_specs). - %%%========================================================================= %%% Specs. These exist only to shut up dialyzer's warnings %%%========================================================================= --type(gs2_state() :: #gs2_state{}). +-type gs2_state() :: #gs2_state{}. --spec(handle_common_termination/3 :: - (any(), atom(), gs2_state()) -> no_return()). --spec(hibernate/1 :: (gs2_state()) -> no_return()). --spec(pre_hibernate/1 :: (gs2_state()) -> no_return()). --spec(system_terminate/4 :: (_, _, _, gs2_state()) -> no_return()). +-spec handle_common_termination(any(), atom(), gs2_state()) -> no_return(). +-spec hibernate(gs2_state()) -> no_return(). +-spec pre_hibernate(gs2_state()) -> no_return(). +-spec system_terminate(_, _, _, gs2_state()) -> no_return(). --type(millis() :: non_neg_integer()). +-type millis() :: non_neg_integer(). %%%========================================================================= %%% API @@ -276,18 +273,6 @@ %% for handle_pre_hibernate/1 and handle_post_hibernate/1 will result %% in warnings (the same applied for the behaviour_info before). --else. - --export([behaviour_info/1]). - -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) diff --git a/deps/rabbit_common/src/mirrored_supervisor.erl b/deps/rabbit_common/src/mirrored_supervisor.erl index d8f19b1bef..991e354107 100644 --- a/deps/rabbit_common/src/mirrored_supervisor.erl +++ b/deps/rabbit_common/src/mirrored_supervisor.erl @@ -151,10 +151,6 @@ initial_childspecs, child_order}). -%%---------------------------------------------------------------------------- - --ifdef(use_specs). - %%-------------------------------------------------------------------------- %% Callback behaviour %%-------------------------------------------------------------------------- @@ -200,15 +196,6 @@ -spec create_tables() -> Result when Result :: 'ok'. --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> [{init,1}]; -behaviour_info(_Other) -> undefined. - --endif. - %%---------------------------------------------------------------------------- start_link(Group, TxFun, Mod, Args) -> diff --git a/deps/rabbit_common/src/pmon.erl b/deps/rabbit_common/src/pmon.erl index cdfdc1c0c0..f75ecec8e5 100644 --- a/deps/rabbit_common/src/pmon.erl +++ b/deps/rabbit_common/src/pmon.erl @@ -36,8 +36,6 @@ -record(state, {dict, module}). --ifdef(use_specs). - %%---------------------------------------------------------------------------- -export_type([?MODULE/0]). @@ -47,17 +45,15 @@ -type(item() :: pid() | {atom(), node()}). --spec(new/0 :: () -> ?MODULE()). --spec(new/1 :: ('erlang' | 'delegate') -> ?MODULE()). --spec(monitor/2 :: (item(), ?MODULE()) -> ?MODULE()). --spec(monitor_all/2 :: ([item()], ?MODULE()) -> ?MODULE()). --spec(demonitor/2 :: (item(), ?MODULE()) -> ?MODULE()). --spec(is_monitored/2 :: (item(), ?MODULE()) -> boolean()). --spec(erase/2 :: (item(), ?MODULE()) -> ?MODULE()). --spec(monitored/1 :: (?MODULE()) -> [item()]). --spec(is_empty/1 :: (?MODULE()) -> boolean()). - --endif. +-spec new() -> ?MODULE(). +-spec new('erlang' | 'delegate') -> ?MODULE(). +-spec monitor(item(), ?MODULE()) -> ?MODULE(). +-spec monitor_all([item()], ?MODULE()) -> ?MODULE(). +-spec demonitor(item(), ?MODULE()) -> ?MODULE(). +-spec is_monitored(item(), ?MODULE()) -> boolean(). +-spec erase(item(), ?MODULE()) -> ?MODULE(). +-spec monitored(?MODULE()) -> [item()]. +-spec is_empty(?MODULE()) -> boolean(). new() -> new(erlang). diff --git a/deps/rabbit_common/src/priority_queue.erl b/deps/rabbit_common/src/priority_queue.erl index 0eab49b3db..81969477c3 100644 --- a/deps/rabbit_common/src/priority_queue.erl +++ b/deps/rabbit_common/src/priority_queue.erl @@ -45,8 +45,6 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([q/0]). -type(q() :: pqueue()). @@ -54,23 +52,21 @@ -type(squeue() :: {queue, [any()], [any()], non_neg_integer()}). -type(pqueue() :: squeue() | {pqueue, [{priority(), squeue()}]}). --spec(new/0 :: () -> pqueue()). --spec(is_queue/1 :: (any()) -> boolean()). --spec(is_empty/1 :: (pqueue()) -> boolean()). --spec(len/1 :: (pqueue()) -> non_neg_integer()). --spec(to_list/1 :: (pqueue()) -> [{priority(), any()}]). --spec(from_list/1 :: ([{priority(), any()}]) -> pqueue()). --spec(in/2 :: (any(), pqueue()) -> pqueue()). --spec(in/3 :: (any(), priority(), pqueue()) -> pqueue()). --spec(out/1 :: (pqueue()) -> {empty | {value, any()}, pqueue()}). --spec(out_p/1 :: (pqueue()) -> {empty | {value, any(), priority()}, pqueue()}). --spec(join/2 :: (pqueue(), pqueue()) -> pqueue()). --spec(filter/2 :: (fun ((any()) -> boolean()), pqueue()) -> pqueue()). --spec(fold/3 :: - (fun ((any(), priority(), A) -> A), A, pqueue()) -> A). --spec(highest/1 :: (pqueue()) -> priority() | 'empty'). - --endif. +-spec new() -> pqueue(). +-spec is_queue(any()) -> boolean(). +-spec is_empty(pqueue()) -> boolean(). +-spec len(pqueue()) -> non_neg_integer(). +-spec to_list(pqueue()) -> [{priority(), any()}]. +-spec from_list([{priority(), any()}]) -> pqueue(). +-spec in(any(), pqueue()) -> pqueue(). +-spec in(any(), priority(), pqueue()) -> pqueue(). +-spec out(pqueue()) -> {empty | {value, any()}, pqueue()}. +-spec out_p(pqueue()) -> {empty | {value, any(), priority()}, pqueue()}. +-spec join(pqueue(), pqueue()) -> pqueue(). +-spec filter(fun ((any()) -> boolean()), pqueue()) -> pqueue(). +-spec fold + (fun ((any(), priority(), A) -> A), A, pqueue()) -> A. +-spec highest(pqueue()) -> priority() | 'empty'. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_amqqueue.erl b/deps/rabbit_common/src/rabbit_amqqueue.erl index 470dd2f850..6d4e52e724 100644 --- a/deps/rabbit_common/src/rabbit_amqqueue.erl +++ b/deps/rabbit_common/src/rabbit_amqqueue.erl @@ -53,162 +53,158 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([name/0, qmsg/0, absent_reason/0]). --type(name() :: rabbit_types:r('queue')). --type(qpids() :: [pid()]). --type(qlen() :: rabbit_types:ok(non_neg_integer())). --type(qfun(A) :: fun ((rabbit_types:amqqueue()) -> A | no_return())). --type(qmsg() :: {name(), pid(), msg_id(), boolean(), rabbit_types:message()}). --type(msg_id() :: non_neg_integer()). --type(ok_or_errors() :: - 'ok' | {'error', [{'error' | 'exit' | 'throw', any()}]}). --type(absent_reason() :: 'nodedown' | 'crashed'). --type(queue_or_absent() :: rabbit_types:amqqueue() | - {'absent', rabbit_types:amqqueue(),absent_reason()}). --type(not_found_or_absent() :: - 'not_found' | {'absent', rabbit_types:amqqueue(), absent_reason()}). --spec(recover/0 :: () -> [rabbit_types:amqqueue()]). --spec(stop/0 :: () -> 'ok'). --spec(start/1 :: ([rabbit_types:amqqueue()]) -> 'ok'). --spec(declare/5 :: - (name(), boolean(), boolean(), - rabbit_framing:amqp_table(), rabbit_types:maybe(pid())) - -> {'new' | 'existing' | 'absent' | 'owner_died', - rabbit_types:amqqueue()} | rabbit_types:channel_exit()). --spec(declare/6 :: - (name(), boolean(), boolean(), - rabbit_framing:amqp_table(), rabbit_types:maybe(pid()), node()) - -> {'new' | 'existing' | 'owner_died', rabbit_types:amqqueue()} | - {'absent', rabbit_types:amqqueue(), absent_reason()} | - rabbit_types:channel_exit()). --spec(internal_declare/2 :: - (rabbit_types:amqqueue(), boolean()) - -> queue_or_absent() | rabbit_misc:thunk(queue_or_absent())). --spec(update/2 :: - (name(), - fun((rabbit_types:amqqueue()) -> rabbit_types:amqqueue())) - -> 'not_found' | rabbit_types:amqqueue()). --spec(lookup/1 :: - (name()) -> rabbit_types:ok(rabbit_types:amqqueue()) | - rabbit_types:error('not_found'); - ([name()]) -> [rabbit_types:amqqueue()]). --spec(not_found_or_absent/1 :: (name()) -> not_found_or_absent()). --spec(with/2 :: (name(), qfun(A)) -> - A | rabbit_types:error(not_found_or_absent())). --spec(with/3 :: (name(), qfun(A), fun((not_found_or_absent()) -> B)) -> A | B). --spec(with_or_die/2 :: - (name(), qfun(A)) -> A | rabbit_types:channel_exit()). --spec(assert_equivalence/5 :: +-type name() :: rabbit_types:r('queue'). +-type qpids() :: [pid()]. +-type qlen() :: rabbit_types:ok(non_neg_integer()). +-type qfun(A) :: fun ((rabbit_types:amqqueue()) -> A | no_return()). +-type qmsg() :: {name(), pid(), msg_id(), boolean(), rabbit_types:message()}. +-type msg_id() :: non_neg_integer(). +-type ok_or_errors() :: + 'ok' | {'error', [{'error' | 'exit' | 'throw', any()}]}. +-type absent_reason() :: 'nodedown' | 'crashed'. +-type queue_or_absent() :: rabbit_types:amqqueue() | + {'absent', rabbit_types:amqqueue(),absent_reason()}. +-type not_found_or_absent() :: + 'not_found' | {'absent', rabbit_types:amqqueue(), absent_reason()}. +-spec recover() -> [rabbit_types:amqqueue()]. +-spec stop() -> 'ok'. +-spec start([rabbit_types:amqqueue()]) -> 'ok'. +-spec declare + (name(), boolean(), boolean(), rabbit_framing:amqp_table(), + rabbit_types:maybe(pid())) -> + {'new' | 'existing' | 'absent' | 'owner_died', + rabbit_types:amqqueue()} | + rabbit_types:channel_exit(). +-spec declare + (name(), boolean(), boolean(), rabbit_framing:amqp_table(), + rabbit_types:maybe(pid()), node()) -> + {'new' | 'existing' | 'owner_died', rabbit_types:amqqueue()} | + {'absent', rabbit_types:amqqueue(), absent_reason()} | + rabbit_types:channel_exit(). +-spec internal_declare(rabbit_types:amqqueue(), boolean()) -> + queue_or_absent() | rabbit_misc:thunk(queue_or_absent()). +-spec update + (name(), fun((rabbit_types:amqqueue()) -> rabbit_types:amqqueue())) -> + 'not_found' | rabbit_types:amqqueue(). +-spec lookup + (name()) -> + rabbit_types:ok(rabbit_types:amqqueue()) | + rabbit_types:error('not_found'); + ([name()]) -> + [rabbit_types:amqqueue()]. +-spec not_found_or_absent(name()) -> not_found_or_absent(). +-spec with(name(), qfun(A)) -> + A | rabbit_types:error(not_found_or_absent()). +-spec with(name(), qfun(A), fun((not_found_or_absent()) -> B)) -> A | B. +-spec with_or_die(name(), qfun(A)) -> A | rabbit_types:channel_exit(). +-spec assert_equivalence (rabbit_types:amqqueue(), boolean(), boolean(), - rabbit_framing:amqp_table(), rabbit_types:maybe(pid())) - -> 'ok' | rabbit_types:channel_exit() | - rabbit_types:connection_exit()). --spec(check_exclusive_access/2 :: - (rabbit_types:amqqueue(), pid()) - -> 'ok' | rabbit_types:channel_exit()). --spec(with_exclusive_access_or_die/3 :: - (name(), pid(), qfun(A)) -> A | rabbit_types:channel_exit()). --spec(list/0 :: () -> [rabbit_types:amqqueue()]). --spec(list/1 :: (rabbit_types:vhost()) -> [rabbit_types:amqqueue()]). --spec(list_down/1 :: (rabbit_types:vhost()) -> [rabbit_types:amqqueue()]). --spec(info_keys/0 :: () -> rabbit_types:info_keys()). --spec(info/1 :: (rabbit_types:amqqueue()) -> rabbit_types:infos()). --spec(info/2 :: - (rabbit_types:amqqueue(), rabbit_types:info_keys()) - -> rabbit_types:infos()). --spec(info_all/1 :: (rabbit_types:vhost()) -> [rabbit_types:infos()]). --spec(info_all/2 :: (rabbit_types:vhost(), rabbit_types:info_keys()) - -> [rabbit_types:infos()]). --spec(info_all/4 :: (rabbit_types:vhost(), rabbit_types:info_keys(), - reference(), pid()) -> 'ok'). --spec(force_event_refresh/1 :: (reference()) -> 'ok'). --spec(notify_policy_changed/1 :: (rabbit_types:amqqueue()) -> 'ok'). --spec(consumers/1 :: (rabbit_types:amqqueue()) - -> [{pid(), rabbit_types:ctag(), boolean(), - non_neg_integer(), rabbit_framing:amqp_table()}]). --spec(consumer_info_keys/0 :: () -> rabbit_types:info_keys()). --spec(consumers_all/1 :: - (rabbit_types:vhost()) - -> [{name(), pid(), rabbit_types:ctag(), boolean(), - non_neg_integer(), rabbit_framing:amqp_table()}]). --spec(consumers_all/3 :: - (rabbit_types:vhost(), reference(), pid()) - -> 'ok'). --spec(stat/1 :: - (rabbit_types:amqqueue()) - -> {'ok', non_neg_integer(), non_neg_integer()}). --spec(delete_immediately/1 :: (qpids()) -> 'ok'). --spec(delete/3 :: - (rabbit_types:amqqueue(), 'false', 'false') - -> qlen(); - (rabbit_types:amqqueue(), 'true' , 'false') - -> qlen() | rabbit_types:error('in_use'); - (rabbit_types:amqqueue(), 'false', 'true' ) - -> qlen() | rabbit_types:error('not_empty'); - (rabbit_types:amqqueue(), 'true' , 'true' ) - -> qlen() | - rabbit_types:error('in_use') | - rabbit_types:error('not_empty')). --spec(delete_crashed/1 :: (rabbit_types:amqqueue()) -> 'ok'). --spec(delete_crashed_internal/1 :: (rabbit_types:amqqueue()) -> 'ok'). --spec(purge/1 :: (rabbit_types:amqqueue()) -> qlen()). --spec(forget_all_durable/1 :: (node()) -> 'ok'). --spec(deliver/2 :: ([rabbit_types:amqqueue()], rabbit_types:delivery()) -> - qpids()). --spec(requeue/3 :: (pid(), [msg_id()], pid()) -> 'ok'). --spec(ack/3 :: (pid(), [msg_id()], pid()) -> 'ok'). --spec(reject/4 :: (pid(), [msg_id()], boolean(), pid()) -> 'ok'). --spec(notify_down_all/2 :: (qpids(), pid()) -> ok_or_errors()). --spec(notify_down_all/3 :: (qpids(), pid(), non_neg_integer()) - -> ok_or_errors()). --spec(activate_limit_all/2 :: (qpids(), pid()) -> ok_or_errors()). --spec(basic_get/4 :: (rabbit_types:amqqueue(), pid(), boolean(), pid()) -> - {'ok', non_neg_integer(), qmsg()} | 'empty'). --spec(credit/5 :: (rabbit_types:amqqueue(), pid(), rabbit_types:ctag(), - non_neg_integer(), boolean()) -> 'ok'). --spec(basic_consume/10 :: + rabbit_framing:amqp_table(), rabbit_types:maybe(pid())) -> + 'ok' | rabbit_types:channel_exit() | rabbit_types:connection_exit(). +-spec check_exclusive_access(rabbit_types:amqqueue(), pid()) -> + 'ok' | rabbit_types:channel_exit(). +-spec with_exclusive_access_or_die(name(), pid(), qfun(A)) -> + A | rabbit_types:channel_exit(). +-spec list() -> [rabbit_types:amqqueue()]. +-spec list(rabbit_types:vhost()) -> [rabbit_types:amqqueue()]. +-spec list_down(rabbit_types:vhost()) -> [rabbit_types:amqqueue()]. +-spec info_keys() -> rabbit_types:info_keys(). +-spec info(rabbit_types:amqqueue()) -> rabbit_types:infos(). +-spec info(rabbit_types:amqqueue(), rabbit_types:info_keys()) -> + rabbit_types:infos(). +-spec info_all(rabbit_types:vhost()) -> [rabbit_types:infos()]. +-spec info_all(rabbit_types:vhost(), rabbit_types:info_keys()) -> + [rabbit_types:infos()]. +-spec info_all + (rabbit_types:vhost(), rabbit_types:info_keys(), boolean(), boolean(), + reference(), pid()) -> + 'ok'. +-spec force_event_refresh(reference()) -> 'ok'. +-spec notify_policy_changed(rabbit_types:amqqueue()) -> 'ok'. +-spec consumers(rabbit_types:amqqueue()) -> + [{pid(), rabbit_types:ctag(), boolean(), non_neg_integer(), + rabbit_framing:amqp_table()}]. +-spec consumer_info_keys() -> rabbit_types:info_keys(). +-spec consumers_all(rabbit_types:vhost()) -> + [{name(), pid(), rabbit_types:ctag(), boolean(), + non_neg_integer(), rabbit_framing:amqp_table()}]. +-spec consumers_all(rabbit_types:vhost(), reference(), pid()) -> 'ok'. +-spec stat(rabbit_types:amqqueue()) -> + {'ok', non_neg_integer(), non_neg_integer()}. +-spec delete_immediately(qpids()) -> 'ok'. +-spec delete + (rabbit_types:amqqueue(), 'false', 'false') -> + qlen(); + (rabbit_types:amqqueue(), 'true' , 'false') -> + qlen() | rabbit_types:error('in_use'); + (rabbit_types:amqqueue(), 'false', 'true' ) -> + qlen() | rabbit_types:error('not_empty'); + (rabbit_types:amqqueue(), 'true' , 'true' ) -> + qlen() | + rabbit_types:error('in_use') | + rabbit_types:error('not_empty'). +-spec delete_crashed(rabbit_types:amqqueue()) -> 'ok'. +-spec delete_crashed_internal(rabbit_types:amqqueue()) -> 'ok'. +-spec purge(rabbit_types:amqqueue()) -> qlen(). +-spec forget_all_durable(node()) -> 'ok'. +-spec deliver([rabbit_types:amqqueue()], rabbit_types:delivery()) -> + qpids(). +-spec requeue(pid(), [msg_id()], pid()) -> 'ok'. +-spec ack(pid(), [msg_id()], pid()) -> 'ok'. +-spec reject(pid(), [msg_id()], boolean(), pid()) -> 'ok'. +-spec notify_down_all(qpids(), pid()) -> ok_or_errors(). +-spec notify_down_all(qpids(), pid(), non_neg_integer()) -> + ok_or_errors(). +-spec activate_limit_all(qpids(), pid()) -> ok_or_errors(). +-spec basic_get(rabbit_types:amqqueue(), pid(), boolean(), pid()) -> + {'ok', non_neg_integer(), qmsg()} | 'empty'. +-spec credit + (rabbit_types:amqqueue(), pid(), rabbit_types:ctag(), non_neg_integer(), + boolean()) -> + 'ok'. +-spec basic_consume (rabbit_types:amqqueue(), boolean(), pid(), pid(), boolean(), non_neg_integer(), rabbit_types:ctag(), boolean(), - rabbit_framing:amqp_table(), any()) - -> rabbit_types:ok_or_error('exclusive_consume_unavailable')). --spec(basic_cancel/4 :: - (rabbit_types:amqqueue(), pid(), rabbit_types:ctag(), any()) -> 'ok'). --spec(notify_decorators/1 :: (rabbit_types:amqqueue()) -> 'ok'). --spec(notify_sent/2 :: (pid(), pid()) -> 'ok'). --spec(notify_sent_queue_down/1 :: (pid()) -> 'ok'). --spec(resume/2 :: (pid(), pid()) -> 'ok'). --spec(internal_delete/1 :: - (name()) -> rabbit_types:ok_or_error('not_found') | - rabbit_types:connection_exit() | - fun (() -> rabbit_types:ok_or_error('not_found') | - rabbit_types:connection_exit())). --spec(run_backing_queue/3 :: - (pid(), atom(), - (fun ((atom(), A) -> {[rabbit_types:msg_id()], A}))) -> 'ok'). --spec(set_ram_duration_target/2 :: (pid(), number() | 'infinity') -> 'ok'). --spec(set_maximum_since_use/2 :: (pid(), non_neg_integer()) -> 'ok'). --spec(on_node_up/1 :: (node()) -> 'ok'). --spec(on_node_down/1 :: (node()) -> 'ok'). --spec(pseudo_queue/2 :: (name(), pid()) -> rabbit_types:amqqueue()). --spec(immutable/1 :: (rabbit_types:amqqueue()) -> rabbit_types:amqqueue()). --spec(store_queue/1 :: (rabbit_types:amqqueue()) -> 'ok'). --spec(update_decorators/1 :: (name()) -> 'ok'). --spec(policy_changed/2 :: - (rabbit_types:amqqueue(), rabbit_types:amqqueue()) -> 'ok'). --spec(start_mirroring/1 :: (pid()) -> 'ok'). --spec(stop_mirroring/1 :: (pid()) -> 'ok'). --spec(sync_mirrors/1 :: (rabbit_types:amqqueue() | pid()) -> 'ok' | rabbit_types:error('not_mirrored')). --spec(cancel_sync_mirrors/1 :: (rabbit_types:amqqueue() | pid()) -> 'ok' | {'ok', 'not_syncing'}). - --spec(pid_of/1 :: (rabbit_types:amqqueue()) -> - {'ok', pid()} | rabbit_types:error('not_found')). --spec(pid_of/2 :: (rabbit_types:vhost(), rabbit_misc:resource_name()) -> - {'ok', pid()} | rabbit_types:error('not_found')). - --endif. + rabbit_framing:amqp_table(), any()) -> + rabbit_types:ok_or_error('exclusive_consume_unavailable'). +-spec basic_cancel + (rabbit_types:amqqueue(), pid(), rabbit_types:ctag(), any()) -> 'ok'. +-spec notify_decorators(rabbit_types:amqqueue()) -> 'ok'. +-spec notify_sent(pid(), pid()) -> 'ok'. +-spec notify_sent_queue_down(pid()) -> 'ok'. +-spec resume(pid(), pid()) -> 'ok'. +-spec internal_delete(name()) -> + rabbit_types:ok_or_error('not_found') | + rabbit_types:connection_exit() | + fun (() -> + rabbit_types:ok_or_error('not_found') | + rabbit_types:connection_exit()). +-spec run_backing_queue + (pid(), atom(), (fun ((atom(), A) -> {[rabbit_types:msg_id()], A}))) -> + 'ok'. +-spec set_ram_duration_target(pid(), number() | 'infinity') -> 'ok'. +-spec set_maximum_since_use(pid(), non_neg_integer()) -> 'ok'. +-spec on_node_up(node()) -> 'ok'. +-spec on_node_down(node()) -> 'ok'. +-spec pseudo_queue(name(), pid()) -> rabbit_types:amqqueue(). +-spec immutable(rabbit_types:amqqueue()) -> rabbit_types:amqqueue(). +-spec store_queue(rabbit_types:amqqueue()) -> 'ok'. +-spec update_decorators(name()) -> 'ok'. +-spec policy_changed(rabbit_types:amqqueue(), rabbit_types:amqqueue()) -> + 'ok'. +-spec start_mirroring(pid()) -> 'ok'. +-spec stop_mirroring(pid()) -> 'ok'. +-spec sync_mirrors(rabbit_types:amqqueue() | pid()) -> + 'ok' | rabbit_types:error('not_mirrored'). +-spec cancel_sync_mirrors(rabbit_types:amqqueue() | pid()) -> + 'ok' | {'ok', 'not_syncing'}. + +-spec pid_of(rabbit_types:amqqueue()) -> + {'ok', pid()} | rabbit_types:error('not_found'). +-spec pid_of(rabbit_types:vhost(), rabbit_misc:resource_name()) -> + {'ok', pid()} | rabbit_types:error('not_found'). %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_auth_backend_dummy.erl b/deps/rabbit_common/src/rabbit_auth_backend_dummy.erl index 0077b4c993..8ac19299f9 100644 --- a/deps/rabbit_common/src/rabbit_auth_backend_dummy.erl +++ b/deps/rabbit_common/src/rabbit_auth_backend_dummy.erl @@ -24,11 +24,7 @@ -export([user_login_authentication/2, user_login_authorization/1, check_vhost_access/3, check_resource_access/3]). --ifdef(use_specs). - --spec(user/0 :: () -> rabbit_types:user()). - --endif. +-spec user() -> rabbit_types:user(). %% A user to be used by the direct client when permission checks are %% not needed. This user can do anything AMQPish. diff --git a/deps/rabbit_common/src/rabbit_auth_backend_internal.erl b/deps/rabbit_common/src/rabbit_auth_backend_internal.erl index 3e9a43c185..fdd954a4e0 100644 --- a/deps/rabbit_common/src/rabbit_auth_backend_internal.erl +++ b/deps/rabbit_common/src/rabbit_auth_backend_internal.erl @@ -40,48 +40,46 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - --type(regexp() :: binary()). - --spec(add_user/2 :: (rabbit_types:username(), rabbit_types:password()) -> 'ok'). --spec(delete_user/1 :: (rabbit_types:username()) -> 'ok'). --spec(lookup_user/1 :: (rabbit_types:username()) - -> rabbit_types:ok(rabbit_types:internal_user()) - | rabbit_types:error('not_found')). --spec(change_password/2 :: (rabbit_types:username(), rabbit_types:password()) - -> 'ok'). --spec(clear_password/1 :: (rabbit_types:username()) -> 'ok'). --spec(hash_password/2 :: (module(), rabbit_types:password()) - -> rabbit_types:password_hash()). --spec(change_password_hash/2 :: (rabbit_types:username(), - rabbit_types:password_hash()) -> 'ok'). --spec(set_tags/2 :: (rabbit_types:username(), [atom()]) -> 'ok'). --spec(set_permissions/5 ::(rabbit_types:username(), rabbit_types:vhost(), - regexp(), regexp(), regexp()) -> 'ok'). --spec(clear_permissions/2 :: (rabbit_types:username(), rabbit_types:vhost()) - -> 'ok'). --spec(user_info_keys/0 :: () -> rabbit_types:info_keys()). --spec(perms_info_keys/0 :: () -> rabbit_types:info_keys()). --spec(user_perms_info_keys/0 :: () -> rabbit_types:info_keys()). --spec(vhost_perms_info_keys/0 :: () -> rabbit_types:info_keys()). --spec(user_vhost_perms_info_keys/0 :: () -> rabbit_types:info_keys()). --spec(list_users/0 :: () -> [rabbit_types:infos()]). --spec(list_users/2 :: (reference(), pid()) -> 'ok'). --spec(list_permissions/0 :: () -> [rabbit_types:infos()]). --spec(list_user_permissions/1 :: - (rabbit_types:username()) -> [rabbit_types:infos()]). --spec(list_user_permissions/3 :: - (rabbit_types:username(), reference(), pid()) -> 'ok'). --spec(list_vhost_permissions/1 :: - (rabbit_types:vhost()) -> [rabbit_types:infos()]). --spec(list_vhost_permissions/3 :: - (rabbit_types:vhost(), reference(), pid()) -> 'ok'). --spec(list_user_vhost_permissions/2 :: - (rabbit_types:username(), rabbit_types:vhost()) - -> [rabbit_types:infos()]). - --endif. +-type regexp() :: binary(). + +-spec add_user(rabbit_types:username(), rabbit_types:password()) -> 'ok'. +-spec delete_user(rabbit_types:username()) -> 'ok'. +-spec lookup_user + (rabbit_types:username()) -> + rabbit_types:ok(rabbit_types:internal_user()) | + rabbit_types:error('not_found'). +-spec change_password + (rabbit_types:username(), rabbit_types:password()) -> 'ok'. +-spec clear_password(rabbit_types:username()) -> 'ok'. +-spec hash_password + (module(), rabbit_types:password()) -> rabbit_types:password_hash(). +-spec change_password_hash + (rabbit_types:username(), rabbit_types:password_hash()) -> 'ok'. +-spec set_tags(rabbit_types:username(), [atom()]) -> 'ok'. +-spec set_permissions + (rabbit_types:username(), rabbit_types:vhost(), regexp(), regexp(), + regexp()) -> + 'ok'. +-spec clear_permissions + (rabbit_types:username(), rabbit_types:vhost()) -> 'ok'. +-spec user_info_keys() -> rabbit_types:info_keys(). +-spec perms_info_keys() -> rabbit_types:info_keys(). +-spec user_perms_info_keys() -> rabbit_types:info_keys(). +-spec vhost_perms_info_keys() -> rabbit_types:info_keys(). +-spec user_vhost_perms_info_keys() -> rabbit_types:info_keys(). +-spec list_users() -> [rabbit_types:infos()]. +-spec list_users(reference(), pid()) -> 'ok'. +-spec list_permissions() -> [rabbit_types:infos()]. +-spec list_user_permissions + (rabbit_types:username()) -> [rabbit_types:infos()]. +-spec list_user_permissions + (rabbit_types:username(), reference(), pid()) -> 'ok'. +-spec list_vhost_permissions + (rabbit_types:vhost()) -> [rabbit_types:infos()]. +-spec list_vhost_permissions + (rabbit_types:vhost(), reference(), pid()) -> 'ok'. +-spec list_user_vhost_permissions + (rabbit_types:username(), rabbit_types:vhost()) -> [rabbit_types:infos()]. %%---------------------------------------------------------------------------- %% Implementation of rabbit_auth_backend diff --git a/deps/rabbit_common/src/rabbit_auth_mechanism.erl b/deps/rabbit_common/src/rabbit_auth_mechanism.erl index c50a429a6f..4c41502b06 100644 --- a/deps/rabbit_common/src/rabbit_auth_mechanism.erl +++ b/deps/rabbit_common/src/rabbit_auth_mechanism.erl @@ -16,8 +16,6 @@ -module(rabbit_auth_mechanism). --ifdef(use_specs). - %% A description. -callback description() -> [proplists:property()]. @@ -43,14 +41,3 @@ {'challenge', binary(), any()} | {'protocol_error', string(), [any()]} | {'refused', rabbit_types:username() | none, string(), [any()]}. - --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{description, 0}, {should_offer, 1}, {init, 1}, {handle_response, 2}]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_authn_backend.erl b/deps/rabbit_common/src/rabbit_authn_backend.erl index 47404df87a..45f3c46109 100644 --- a/deps/rabbit_common/src/rabbit_authn_backend.erl +++ b/deps/rabbit_common/src/rabbit_authn_backend.erl @@ -18,8 +18,6 @@ -include("rabbit.hrl"). --ifdef(use_specs). - %% Check a user can log in, given a username and a proplist of %% authentication information (e.g. [{password, Password}]). If your %% backend is not to be used for authentication, this should always @@ -36,14 +34,3 @@ {'ok', rabbit_types:auth_user()} | {'refused', string(), [any()]} | {'error', any()}. - --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{user_login_authentication, 2}]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_authz_backend.erl b/deps/rabbit_common/src/rabbit_authz_backend.erl index 331de8f0bd..4315aaa9b1 100644 --- a/deps/rabbit_common/src/rabbit_authz_backend.erl +++ b/deps/rabbit_common/src/rabbit_authz_backend.erl @@ -18,8 +18,6 @@ -include("rabbit.hrl"). --ifdef(use_specs). - %% Check a user can log in, when this backend is being used for %% authorisation only. Authentication has already taken place %% successfully, but we need to check that the user exists in this @@ -62,15 +60,3 @@ rabbit_types:r(atom()), rabbit_access_control:permission_atom()) -> boolean() | {'error', any()}. - --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{user_login_authorization, 1}, - {check_vhost_access, 3}, {check_resource_access, 3}]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_backing_queue.erl b/deps/rabbit_common/src/rabbit_backing_queue.erl index 862dbc9413..bb4d03acce 100644 --- a/deps/rabbit_common/src/rabbit_backing_queue.erl +++ b/deps/rabbit_common/src/rabbit_backing_queue.erl @@ -25,35 +25,33 @@ message_bytes_persistent, head_message_timestamp, disk_reads, disk_writes, backing_queue_status]). --ifdef(use_specs). - %% We can't specify a per-queue ack/state with callback signatures --type(ack() :: any()). --type(state() :: any()). - --type(flow() :: 'flow' | 'noflow'). --type(msg_ids() :: [rabbit_types:msg_id()]). --type(publish() :: {rabbit_types:basic_message(), - rabbit_types:message_properties(), boolean()}). --type(delivered_publish() :: {rabbit_types:basic_message(), - rabbit_types:message_properties()}). --type(fetch_result(Ack) :: - ('empty' | {rabbit_types:basic_message(), boolean(), Ack})). --type(drop_result(Ack) :: - ('empty' | {rabbit_types:msg_id(), Ack})). --type(recovery_terms() :: [term()] | 'non_clean_shutdown'). --type(recovery_info() :: 'new' | recovery_terms()). --type(purged_msg_count() :: non_neg_integer()). --type(async_callback() :: - fun ((atom(), fun ((atom(), state()) -> state())) -> 'ok')). --type(duration() :: ('undefined' | 'infinity' | number())). - --type(msg_fun(A) :: fun ((rabbit_types:basic_message(), ack(), A) -> A)). --type(msg_pred() :: fun ((rabbit_types:message_properties()) -> boolean())). - --type(queue_mode() :: atom()). - --spec(info_keys/0 :: () -> rabbit_types:info_keys()). +-type ack() :: any(). +-type state() :: any(). + +-type flow() :: 'flow' | 'noflow'. +-type msg_ids() :: [rabbit_types:msg_id()]. +-type publish() :: {rabbit_types:basic_message(), + rabbit_types:message_properties(), boolean()}. +-type delivered_publish() :: {rabbit_types:basic_message(), + rabbit_types:message_properties()}. +-type fetch_result(Ack) :: + ('empty' | {rabbit_types:basic_message(), boolean(), Ack}). +-type drop_result(Ack) :: + ('empty' | {rabbit_types:msg_id(), Ack}). +-type recovery_terms() :: [term()] | 'non_clean_shutdown'. +-type recovery_info() :: 'new' | recovery_terms(). +-type purged_msg_count() :: non_neg_integer(). +-type async_callback() :: + fun ((atom(), fun ((atom(), state()) -> state())) -> 'ok'). +-type duration() :: ('undefined' | 'infinity' | number()). + +-type msg_fun(A) :: fun ((rabbit_types:basic_message(), ack(), A) -> A). +-type msg_pred() :: fun ((rabbit_types:message_properties()) -> boolean()). + +-type queue_mode() :: atom(). + +-spec info_keys() -> rabbit_types:info_keys(). %% Called on startup with a list of durable queue names. The queues %% aren't being started at this point, but this call allows the @@ -266,26 +264,4 @@ [ack()], Acc, state()) -> Acc. --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{start, 1}, {stop, 0}, {init, 3}, {terminate, 2}, - {delete_and_terminate, 2}, {delete_crashed, 1}, {purge, 1}, - {purge_acks, 1}, {publish, 6}, {publish_delivered, 5}, - {batch_publish, 4}, {batch_publish_delivered, 4}, - {discard, 4}, {drain_confirmed, 1}, - {dropwhile, 2}, {fetchwhile, 4}, {fetch, 2}, - {drop, 2}, {ack, 2}, {requeue, 2}, {ackfold, 4}, {fold, 3}, {len, 1}, - {is_empty, 1}, {depth, 1}, {set_ram_duration_target, 2}, - {ram_duration, 1}, {needs_timeout, 1}, {timeout, 1}, - {handle_pre_hibernate, 1}, {resume, 1}, {msg_rates, 1}, - {info, 2}, {invoke, 3}, {is_duplicate, 2}, {set_queue_mode, 2}, - {zip_msgs_and_acks, 4}]; -behaviour_info(_Other) -> - undefined. - --endif. - info_keys() -> ?INFO_KEYS. diff --git a/deps/rabbit_common/src/rabbit_basic.erl b/deps/rabbit_common/src/rabbit_basic.erl index ed71d8ba80..14f0a4e855 100644 --- a/deps/rabbit_common/src/rabbit_basic.erl +++ b/deps/rabbit_common/src/rabbit_basic.erl @@ -26,69 +26,67 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). +-type properties_input() :: + rabbit_framing:amqp_property_record() | [{atom(), any()}]. +-type publish_result() :: + {ok, [pid()]} | rabbit_types:error('not_found'). +-type header() :: any(). +-type headers() :: rabbit_framing:amqp_table() | 'undefined'. --type(properties_input() :: - (rabbit_framing:amqp_property_record() | [{atom(), any()}])). --type(publish_result() :: - ({ok, [pid()]} | rabbit_types:error('not_found'))). --type(header() :: any()). --type(headers() :: rabbit_framing:amqp_table() | 'undefined'). +-type exchange_input() :: rabbit_types:exchange() | rabbit_exchange:name(). +-type body_input() :: binary() | [binary()]. --type(exchange_input() :: (rabbit_types:exchange() | rabbit_exchange:name())). --type(body_input() :: (binary() | [binary()])). - --spec(publish/4 :: +-spec publish (exchange_input(), rabbit_router:routing_key(), properties_input(), - body_input()) -> publish_result()). --spec(publish/5 :: + body_input()) -> + publish_result(). +-spec publish (exchange_input(), rabbit_router:routing_key(), boolean(), - properties_input(), body_input()) -> publish_result()). --spec(publish/1 :: - (rabbit_types:delivery()) -> publish_result()). --spec(delivery/4 :: + properties_input(), body_input()) -> + publish_result(). +-spec publish(rabbit_types:delivery()) -> publish_result(). +-spec delivery (boolean(), boolean(), rabbit_types:message(), undefined | integer()) -> - rabbit_types:delivery()). --spec(message/4 :: - (rabbit_exchange:name(), rabbit_router:routing_key(), - properties_input(), binary()) -> rabbit_types:message()). --spec(message/3 :: + rabbit_types:delivery(). +-spec message + (rabbit_exchange:name(), rabbit_router:routing_key(), properties_input(), + binary()) -> + rabbit_types:message(). +-spec message (rabbit_exchange:name(), rabbit_router:routing_key(), rabbit_types:decoded_content()) -> - rabbit_types:ok_or_error2(rabbit_types:message(), any())). --spec(properties/1 :: - (properties_input()) -> rabbit_framing:amqp_property_record()). - --spec(prepend_table_header/3 :: - (binary(), rabbit_framing:amqp_table(), headers()) -> headers()). - --spec(header/2 :: - (header(), headers()) -> 'undefined' | any()). --spec(header/3 :: - (header(), headers(), any()) -> 'undefined' | any()). - --spec(extract_headers/1 :: (rabbit_types:content()) -> headers()). - --spec(map_headers/2 :: (fun((headers()) -> headers()), rabbit_types:content()) - -> rabbit_types:content()). - --spec(header_routes/1 :: - (undefined | rabbit_framing:amqp_table()) -> [string()]). --spec(build_content/2 :: (rabbit_framing:amqp_property_record(), - binary() | [binary()]) -> rabbit_types:content()). --spec(from_content/1 :: (rabbit_types:content()) -> - {rabbit_framing:amqp_property_record(), binary()}). --spec(parse_expiration/1 :: - (rabbit_framing:amqp_property_record()) - -> rabbit_types:ok_or_error2('undefined' | non_neg_integer(), any())). - --spec(msg_size/1 :: (rabbit_types:content() | rabbit_types:message()) -> - non_neg_integer()). - --spec(maybe_gc_large_msg/1 :: - (rabbit_types:content() | rabbit_types:message()) -> non_neg_integer()). - --endif. + rabbit_types:ok_or_error2(rabbit_types:message(), any()). +-spec properties + (properties_input()) -> rabbit_framing:amqp_property_record(). + +-spec prepend_table_header + (binary(), rabbit_framing:amqp_table(), headers()) -> headers(). + +-spec header(header(), headers()) -> 'undefined' | any(). +-spec header(header(), headers(), any()) -> 'undefined' | any(). + +-spec extract_headers(rabbit_types:content()) -> headers(). + +-spec map_headers + (fun((headers()) -> headers()), rabbit_types:content()) -> + rabbit_types:content(). + +-spec header_routes(undefined | rabbit_framing:amqp_table()) -> [string()]. +-spec build_content + (rabbit_framing:amqp_property_record(), binary() | [binary()]) -> + rabbit_types:content(). +-spec from_content + (rabbit_types:content()) -> + {rabbit_framing:amqp_property_record(), binary()}. +-spec parse_expiration + (rabbit_framing:amqp_property_record()) -> + rabbit_types:ok_or_error2('undefined' | non_neg_integer(), any()). + +-spec msg_size + (rabbit_types:content() | rabbit_types:message()) -> non_neg_integer(). + +-spec maybe_gc_large_msg + (rabbit_types:content() | rabbit_types:message()) -> non_neg_integer(). %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_binary_generator.erl b/deps/rabbit_common/src/rabbit_binary_generator.erl index a2a80d7b0e..95d06ff5f5 100644 --- a/deps/rabbit_common/src/rabbit_binary_generator.erl +++ b/deps/rabbit_common/src/rabbit_binary_generator.erl @@ -28,33 +28,30 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). +-type frame() :: [binary()]. --type(frame() :: [binary()]). - --spec(build_simple_method_frame/3 :: +-spec build_simple_method_frame (rabbit_channel:channel_number(), rabbit_framing:amqp_method_record(), - rabbit_types:protocol()) - -> frame()). --spec(build_simple_content_frames/4 :: + rabbit_types:protocol()) -> + frame(). +-spec build_simple_content_frames (rabbit_channel:channel_number(), rabbit_types:content(), - non_neg_integer(), rabbit_types:protocol()) - -> [frame()]). --spec(build_heartbeat_frame/0 :: () -> frame()). --spec(generate_table/1 :: (rabbit_framing:amqp_table()) -> binary()). --spec(check_empty_frame_size/0 :: () -> 'ok'). --spec(ensure_content_encoded/2 :: + non_neg_integer(), rabbit_types:protocol()) -> + [frame()]. +-spec build_heartbeat_frame() -> frame(). +-spec generate_table(rabbit_framing:amqp_table()) -> binary(). +-spec check_empty_frame_size() -> 'ok'. +-spec ensure_content_encoded (rabbit_types:content(), rabbit_types:protocol()) -> - rabbit_types:encoded_content()). --spec(clear_encoded_content/1 :: - (rabbit_types:content()) -> rabbit_types:unencoded_content()). --spec(map_exception/3 :: (rabbit_channel:channel_number(), - rabbit_types:amqp_error() | any(), - rabbit_types:protocol()) -> - {rabbit_channel:channel_number(), - rabbit_framing:amqp_method_record()}). - --endif. + rabbit_types:encoded_content(). +-spec clear_encoded_content + (rabbit_types:content()) -> + rabbit_types:unencoded_content(). +-spec map_exception + (rabbit_channel:channel_number(), rabbit_types:amqp_error() | any(), + rabbit_types:protocol()) -> + {rabbit_channel:channel_number(), + rabbit_framing:amqp_method_record()}. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_binary_parser.erl b/deps/rabbit_common/src/rabbit_binary_parser.erl index db8aca907d..b84e1203f9 100644 --- a/deps/rabbit_common/src/rabbit_binary_parser.erl +++ b/deps/rabbit_common/src/rabbit_binary_parser.erl @@ -24,17 +24,15 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - --spec(parse_table/1 :: (binary()) -> rabbit_framing:amqp_table()). --spec(ensure_content_decoded/1 :: - (rabbit_types:content()) -> rabbit_types:decoded_content()). --spec(clear_decoded_content/1 :: - (rabbit_types:content()) -> rabbit_types:undecoded_content()). --spec(validate_utf8/1 :: (binary()) -> 'ok' | 'error'). --spec(assert_utf8/1 :: (binary()) -> 'ok'). - --endif. +-spec parse_table(binary()) -> rabbit_framing:amqp_table(). +-spec ensure_content_decoded + (rabbit_types:content()) -> + rabbit_types:decoded_content(). +-spec clear_decoded_content + (rabbit_types:content()) -> + rabbit_types:undecoded_content(). +-spec validate_utf8(binary()) -> 'ok' | 'error'. +-spec assert_utf8(binary()) -> 'ok'. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_channel.erl b/deps/rabbit_common/src/rabbit_channel.erl index 7850593406..c915fab81e 100644 --- a/deps/rabbit_common/src/rabbit_channel.erl +++ b/deps/rabbit_common/src/rabbit_channel.erl @@ -180,51 +180,48 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([channel_number/0]). --type(channel_number() :: non_neg_integer()). +-type channel_number() :: non_neg_integer(). -export_type([channel/0]). --type(channel() :: #ch{}). - --spec(start_link/11 :: - (channel_number(), pid(), pid(), pid(), string(), - rabbit_types:protocol(), rabbit_types:user(), rabbit_types:vhost(), - rabbit_framing:amqp_table(), pid(), pid()) -> - rabbit_types:ok_pid_or_error()). --spec(do/2 :: (pid(), rabbit_framing:amqp_method_record()) -> 'ok'). --spec(do/3 :: (pid(), rabbit_framing:amqp_method_record(), - rabbit_types:maybe(rabbit_types:content())) -> 'ok'). --spec(do_flow/3 :: (pid(), rabbit_framing:amqp_method_record(), - rabbit_types:maybe(rabbit_types:content())) -> 'ok'). --spec(flush/1 :: (pid()) -> 'ok'). --spec(shutdown/1 :: (pid()) -> 'ok'). --spec(send_command/2 :: (pid(), rabbit_framing:amqp_method_record()) -> 'ok'). --spec(deliver/4 :: - (pid(), rabbit_types:ctag(), boolean(), rabbit_amqqueue:qmsg()) - -> 'ok'). --spec(deliver_reply/2 :: (binary(), rabbit_types:delivery()) -> 'ok'). --spec(deliver_reply_local/3 :: - (pid(), binary(), rabbit_types:delivery()) -> 'ok'). --spec(send_credit_reply/2 :: (pid(), non_neg_integer()) -> 'ok'). --spec(send_drained/2 :: (pid(), [{rabbit_types:ctag(), non_neg_integer()}]) - -> 'ok'). --spec(list/0 :: () -> [pid()]). --spec(list_local/0 :: () -> [pid()]). --spec(info_keys/0 :: () -> rabbit_types:info_keys()). --spec(info/1 :: (pid()) -> rabbit_types:infos()). --spec(info/2 :: (pid(), rabbit_types:info_keys()) -> rabbit_types:infos()). --spec(info_all/0 :: () -> [rabbit_types:infos()]). --spec(info_all/1 :: (rabbit_types:info_keys()) -> [rabbit_types:infos()]). --spec(info_all/3 :: (rabbit_types:info_keys(), reference(), pid()) -> 'ok'). --spec(refresh_config_local/0 :: () -> 'ok'). --spec(ready_for_close/1 :: (pid()) -> 'ok'). --spec(force_event_refresh/1 :: (reference()) -> 'ok'). - --endif. +-type channel() :: #ch{}. + +-spec start_link + (channel_number(), pid(), pid(), pid(), string(), rabbit_types:protocol(), + rabbit_types:user(), rabbit_types:vhost(), rabbit_framing:amqp_table(), + pid(), pid()) -> + rabbit_types:ok_pid_or_error(). +-spec do(pid(), rabbit_framing:amqp_method_record()) -> 'ok'. +-spec do + (pid(), rabbit_framing:amqp_method_record(), + rabbit_types:maybe(rabbit_types:content())) -> + 'ok'. +-spec do_flow + (pid(), rabbit_framing:amqp_method_record(), + rabbit_types:maybe(rabbit_types:content())) -> + 'ok'. +-spec flush(pid()) -> 'ok'. +-spec shutdown(pid()) -> 'ok'. +-spec send_command(pid(), rabbit_framing:amqp_method_record()) -> 'ok'. +-spec deliver + (pid(), rabbit_types:ctag(), boolean(), rabbit_amqqueue:qmsg()) -> 'ok'. +-spec deliver_reply(binary(), rabbit_types:delivery()) -> 'ok'. +-spec deliver_reply_local(pid(), binary(), rabbit_types:delivery()) -> 'ok'. +-spec send_credit_reply(pid(), non_neg_integer()) -> 'ok'. +-spec send_drained(pid(), [{rabbit_types:ctag(), non_neg_integer()}]) -> 'ok'. +-spec list() -> [pid()]. +-spec list_local() -> [pid()]. +-spec info_keys() -> rabbit_types:info_keys(). +-spec info(pid()) -> rabbit_types:infos(). +-spec info(pid(), rabbit_types:info_keys()) -> rabbit_types:infos(). +-spec info_all() -> [rabbit_types:infos()]. +-spec info_all(rabbit_types:info_keys()) -> [rabbit_types:infos()]. +-spec info_all(rabbit_types:info_keys(), reference(), pid()) -> 'ok'. +-spec refresh_config_local() -> 'ok'. +-spec ready_for_close(pid()) -> 'ok'. +-spec force_event_refresh(reference()) -> 'ok'. %%---------------------------------------------------------------------------- @@ -675,14 +672,12 @@ handle_exception(Reason, State = #ch{protocol = Protocol, {stop, normal, State1} end. --ifdef(use_specs). --spec(precondition_failed/1 :: (string()) -> no_return()). --endif. +-spec precondition_failed(string()) -> no_return(). + precondition_failed(Format) -> precondition_failed(Format, []). --ifdef(use_specs). --spec(precondition_failed/2 :: (string(), [any()]) -> no_return()). --endif. +-spec precondition_failed(string(), [any()]) -> no_return(). + precondition_failed(Format, Params) -> rabbit_misc:protocol_error(precondition_failed, Format, Params). diff --git a/deps/rabbit_common/src/rabbit_channel_interceptor.erl b/deps/rabbit_common/src/rabbit_channel_interceptor.erl index 9793459c45..909bf4aecc 100644 --- a/deps/rabbit_common/src/rabbit_channel_interceptor.erl +++ b/deps/rabbit_common/src/rabbit_channel_interceptor.erl @@ -21,8 +21,6 @@ -export([init/1, intercept_in/3]). --ifdef(use_specs). - -type(method_name() :: rabbit_framing:amqp_method_name()). -type(original_method() :: rabbit_framing:amqp_method_record()). -type(processed_method() :: rabbit_framing:amqp_method_record()). @@ -40,17 +38,6 @@ rabbit_misc:channel_or_connection_exit(). -callback applies_to() -> list(method_name()). --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{description, 0}, {init, 1}, {intercept, 3}, {applies_to, 0}]; -behaviour_info(_Other) -> - undefined. - --endif. - init(Ch) -> Mods = [M || {_, M} <- rabbit_registry:lookup_all(channel_interceptor)], check_no_overlap(Mods), diff --git a/deps/rabbit_common/src/rabbit_command_assembler.erl b/deps/rabbit_common/src/rabbit_command_assembler.erl index 49601dbce4..5adf7b1b5f 100644 --- a/deps/rabbit_common/src/rabbit_command_assembler.erl +++ b/deps/rabbit_common/src/rabbit_command_assembler.erl @@ -24,41 +24,37 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([frame/0]). --type(frame_type() :: ?FRAME_METHOD | ?FRAME_HEADER | ?FRAME_BODY | +-type frame_type() :: ?FRAME_METHOD | ?FRAME_HEADER | ?FRAME_BODY | ?FRAME_OOB_METHOD | ?FRAME_OOB_HEADER | ?FRAME_OOB_BODY | - ?FRAME_TRACE | ?FRAME_HEARTBEAT). --type(protocol() :: rabbit_framing:protocol()). --type(method() :: rabbit_framing:amqp_method_record()). --type(class_id() :: rabbit_framing:amqp_class_id()). --type(weight() :: non_neg_integer()). --type(body_size() :: non_neg_integer()). --type(content() :: rabbit_types:undecoded_content()). - --type(frame() :: + ?FRAME_TRACE | ?FRAME_HEARTBEAT. +-type protocol() :: rabbit_framing:protocol(). +-type method() :: rabbit_framing:amqp_method_record(). +-type class_id() :: rabbit_framing:amqp_class_id(). +-type weight() :: non_neg_integer(). +-type body_size() :: non_neg_integer(). +-type content() :: rabbit_types:undecoded_content(). + +-type frame() :: {'method', rabbit_framing:amqp_method_name(), binary()} | {'content_header', class_id(), weight(), body_size(), binary()} | - {'content_body', binary()}). + {'content_body', binary()}. --type(state() :: +-type state() :: {'method', protocol()} | {'content_header', method(), class_id(), protocol()} | - {'content_body', method(), body_size(), class_id(), protocol()}). - --spec(analyze_frame/3 :: (frame_type(), binary(), protocol()) -> - frame() | 'heartbeat' | 'error'). + {'content_body', method(), body_size(), class_id(), protocol()}. --spec(init/1 :: (protocol()) -> {ok, state()}). --spec(process/2 :: (frame(), state()) -> - {ok, state()} | - {ok, method(), state()} | - {ok, method(), content(), state()} | - {error, rabbit_types:amqp_error()}). +-spec analyze_frame(frame_type(), binary(), protocol()) -> + frame() | 'heartbeat' | 'error'. --endif. +-spec init(protocol()) -> {ok, state()}. +-spec process(frame(), state()) -> + {ok, state()} | + {ok, method(), state()} | + {ok, method(), content(), state()} | + {error, rabbit_types:amqp_error()}. %%-------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_control_misc.erl b/deps/rabbit_common/src/rabbit_control_misc.erl index 2e274e858b..0d2de1f1c4 100644 --- a/deps/rabbit_common/src/rabbit_control_misc.erl +++ b/deps/rabbit_common/src/rabbit_control_misc.erl @@ -20,17 +20,13 @@ emitting_map_with_exit_handler/5, wait_for_info_messages/5, print_cmd_result/2]). --ifdef(use_specs). - --spec(emitting_map/4 :: (pid(), reference(), fun(), list()) -> 'ok'). --spec(emitting_map/5 :: (pid(), reference(), fun(), list(), atom()) -> 'ok'). --spec(emitting_map_with_exit_handler/4 :: - (pid(), reference(), fun(), list()) -> 'ok'). --spec(emitting_map_with_exit_handler/5 :: - (pid(), reference(), fun(), list(), atom()) -> 'ok'). --spec(print_cmd_result/2 :: (atom(), term()) -> 'ok'). - --endif. +-spec emitting_map(pid(), reference(), fun(), list()) -> 'ok'. +-spec emitting_map(pid(), reference(), fun(), list(), atom()) -> 'ok'. +-spec emitting_map_with_exit_handler + (pid(), reference(), fun(), list()) -> 'ok'. +-spec emitting_map_with_exit_handler + (pid(), reference(), fun(), list(), atom()) -> 'ok'. +-spec print_cmd_result(atom(), term()) -> 'ok'. emitting_map(AggregatorPid, Ref, Fun, List) -> emitting_map(AggregatorPid, Ref, Fun, List, continue), diff --git a/deps/rabbit_common/src/rabbit_event.erl b/deps/rabbit_common/src/rabbit_event.erl index a0699733e4..bd869dd736 100644 --- a/deps/rabbit_common/src/rabbit_event.erl +++ b/deps/rabbit_common/src/rabbit_event.erl @@ -31,41 +31,36 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([event_type/0, event_props/0, event_timestamp/0, event/0]). --type(event_type() :: atom()). --type(event_props() :: term()). --type(event_timestamp() :: non_neg_integer()). +-type event_type() :: atom(). +-type event_props() :: term(). +-type event_timestamp() :: non_neg_integer(). --type(event() :: #event { type :: event_type(), +-type event() :: #event { type :: event_type(), props :: event_props(), reference :: 'none' | reference(), - timestamp :: event_timestamp() }). - --type(level() :: 'none' | 'coarse' | 'fine'). - --type(timer_fun() :: fun (() -> 'ok')). --type(container() :: tuple()). --type(pos() :: non_neg_integer()). - --spec(start_link/0 :: () -> rabbit_types:ok_pid_or_error()). --spec(init_stats_timer/2 :: (container(), pos()) -> container()). --spec(init_disabled_stats_timer/2 :: (container(), pos()) -> container()). --spec(ensure_stats_timer/3 :: (container(), pos(), term()) -> container()). --spec(stop_stats_timer/2 :: (container(), pos()) -> container()). --spec(reset_stats_timer/2 :: (container(), pos()) -> container()). --spec(stats_level/2 :: (container(), pos()) -> level()). --spec(if_enabled/3 :: (container(), pos(), timer_fun()) -> 'ok'). --spec(notify/2 :: (event_type(), event_props()) -> 'ok'). --spec(notify/3 :: (event_type(), event_props(), reference() | 'none') -> 'ok'). --spec(notify_if/3 :: (boolean(), event_type(), event_props()) -> 'ok'). --spec(sync_notify/2 :: (event_type(), event_props()) -> 'ok'). --spec(sync_notify/3 :: (event_type(), event_props(), - reference() | 'none') -> 'ok'). - --endif. + timestamp :: event_timestamp() }. + +-type level() :: 'none' | 'coarse' | 'fine'. + +-type timer_fun() :: fun (() -> 'ok'). +-type container() :: tuple(). +-type pos() :: non_neg_integer(). + +-spec start_link() -> rabbit_types:ok_pid_or_error(). +-spec init_stats_timer(container(), pos()) -> container(). +-spec init_disabled_stats_timer(container(), pos()) -> container(). +-spec ensure_stats_timer(container(), pos(), term()) -> container(). +-spec stop_stats_timer(container(), pos()) -> container(). +-spec reset_stats_timer(container(), pos()) -> container(). +-spec stats_level(container(), pos()) -> level(). +-spec if_enabled(container(), pos(), timer_fun()) -> 'ok'. +-spec notify(event_type(), event_props()) -> 'ok'. +-spec notify(event_type(), event_props(), reference() | 'none') -> 'ok'. +-spec notify_if(boolean(), event_type(), event_props()) -> 'ok'. +-spec sync_notify(event_type(), event_props()) -> 'ok'. +-spec sync_notify(event_type(), event_props(), reference() | 'none') -> 'ok'. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_exchange_decorator.erl b/deps/rabbit_common/src/rabbit_exchange_decorator.erl index bf57b2aaeb..a43991b275 100644 --- a/deps/rabbit_common/src/rabbit_exchange_decorator.erl +++ b/deps/rabbit_common/src/rabbit_exchange_decorator.erl @@ -29,8 +29,6 @@ %% It's possible in the future we might make decorators %% able to manipulate messages as they are published. --ifdef(use_specs). - -type(tx() :: 'transaction' | 'none'). -type(serial() :: pos_integer() | tx()). @@ -69,19 +67,6 @@ %% none:no callbacks, noroute:all callbacks except route, all:all callbacks -callback active_for(rabbit_types:exchange()) -> 'none' | 'noroute' | 'all'. --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{description, 0}, {serialise_events, 1}, {create, 2}, {delete, 3}, - {policy_changed, 2}, {add_binding, 3}, {remove_bindings, 3}, - {route, 2}, {active_for, 1}]; -behaviour_info(_Other) -> - undefined. - --endif. - %%---------------------------------------------------------------------------- %% select a subset of active decorators diff --git a/deps/rabbit_common/src/rabbit_exchange_type.erl b/deps/rabbit_common/src/rabbit_exchange_type.erl index 0b7fda61f6..5f282d1a3f 100644 --- a/deps/rabbit_common/src/rabbit_exchange_type.erl +++ b/deps/rabbit_common/src/rabbit_exchange_type.erl @@ -16,8 +16,6 @@ -module(rabbit_exchange_type). --ifdef(use_specs). - -type(tx() :: 'transaction' | 'none'). -type(serial() :: pos_integer() | tx()). @@ -65,17 +63,3 @@ -callback assert_args_equivalence(rabbit_types:exchange(), rabbit_framing:amqp_table()) -> 'ok' | rabbit_types:connection_exit(). - --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{description, 0}, {serialise_events, 0}, {route, 2}, - {validate, 1}, {validate_binding, 2}, {policy_changed, 2}, - {create, 2}, {delete, 3}, {add_binding, 3}, {remove_bindings, 3}, - {assert_args_equivalence, 2}]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_health_check.erl b/deps/rabbit_common/src/rabbit_health_check.erl index acef9d94b9..94dbe85c7e 100644 --- a/deps/rabbit_common/src/rabbit_health_check.erl +++ b/deps/rabbit_common/src/rabbit_health_check.erl @@ -19,9 +19,7 @@ -define(NODE_HEALTH_CHECK_TIMEOUT, 70000). --ifdef(use_specs). --spec(node/1 :: (node()) -> 'true' | no_return()). --endif. +-spec node(node()) -> 'true' | no_return(). %%---------------------------------------------------------------------------- %% External functions diff --git a/deps/rabbit_common/src/rabbit_heartbeat.erl b/deps/rabbit_common/src/rabbit_heartbeat.erl index 8610753b4c..c9b366917a 100644 --- a/deps/rabbit_common/src/rabbit_heartbeat.erl +++ b/deps/rabbit_common/src/rabbit_heartbeat.erl @@ -26,39 +26,38 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([heartbeaters/0]). --type(heartbeaters() :: {rabbit_types:maybe(pid()), rabbit_types:maybe(pid())}). +-type heartbeaters() :: {rabbit_types:maybe(pid()), rabbit_types:maybe(pid())}. --type(heartbeat_callback() :: fun (() -> any())). +-type heartbeat_callback() :: fun (() -> any()). --spec(start/6 :: - (pid(), rabbit_net:socket(), - non_neg_integer(), heartbeat_callback(), - non_neg_integer(), heartbeat_callback()) -> heartbeaters()). +-spec start + (pid(), rabbit_net:socket(), non_neg_integer(), heartbeat_callback(), + non_neg_integer(), heartbeat_callback()) -> + heartbeaters(). --spec(start/7 :: +-spec start (pid(), rabbit_net:socket(), rabbit_types:proc_name(), - non_neg_integer(), heartbeat_callback(), - non_neg_integer(), heartbeat_callback()) -> heartbeaters()). + non_neg_integer(), heartbeat_callback(), non_neg_integer(), + heartbeat_callback()) -> + heartbeaters(). --spec(start_heartbeat_sender/4 :: +-spec start_heartbeat_sender (rabbit_net:socket(), non_neg_integer(), heartbeat_callback(), - rabbit_types:proc_type_and_name()) -> rabbit_types:ok(pid())). --spec(start_heartbeat_receiver/4 :: + rabbit_types:proc_type_and_name()) -> + rabbit_types:ok(pid()). +-spec start_heartbeat_receiver (rabbit_net:socket(), non_neg_integer(), heartbeat_callback(), - rabbit_types:proc_type_and_name()) -> rabbit_types:ok(pid())). - --spec(pause_monitor/1 :: (heartbeaters()) -> 'ok'). --spec(resume_monitor/1 :: (heartbeaters()) -> 'ok'). + rabbit_types:proc_type_and_name()) -> + rabbit_types:ok(pid()). --spec(system_code_change/4 :: (_,_,_,_) -> {'ok',_}). --spec(system_continue/3 :: (_,_,{_, _}) -> any()). --spec(system_terminate/4 :: (_,_,_,_) -> none()). +-spec pause_monitor(heartbeaters()) -> 'ok'. +-spec resume_monitor(heartbeaters()) -> 'ok'. --endif. +-spec system_code_change(_,_,_,_) -> {'ok',_}. +-spec system_continue(_,_,{_, _}) -> any(). +-spec system_terminate(_,_,_,_) -> none(). %%---------------------------------------------------------------------------- start(SupPid, Sock, SendTimeoutSec, SendFun, ReceiveTimeoutSec, ReceiveFun) -> diff --git a/deps/rabbit_common/src/rabbit_misc.erl b/deps/rabbit_common/src/rabbit_misc.erl index f2bbb375e0..7331ad1a73 100644 --- a/deps/rabbit_common/src/rabbit_misc.erl +++ b/deps/rabbit_common/src/rabbit_misc.erl @@ -85,195 +85,186 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([resource_name/0, thunk/1, channel_or_connection_exit/0]). --type(ok_or_error() :: rabbit_types:ok_or_error(any())). --type(thunk(T) :: fun(() -> T)). --type(resource_name() :: binary()). --type(channel_or_connection_exit() - :: rabbit_types:channel_exit() | rabbit_types:connection_exit()). --type(digraph_label() :: term()). --type(graph_vertex_fun() :: - fun (({atom(), [term()]}) -> [{digraph:vertex(), digraph_label()}])). --type(graph_edge_fun() :: - fun (({atom(), [term()]}) -> [{digraph:vertex(), digraph:vertex()}])). --type(tref() :: {'erlang', reference()} | {timer, timer:tref()}). - --spec(method_record_type/1 :: (rabbit_framing:amqp_method_record()) - -> rabbit_framing:amqp_method_name()). --spec(polite_pause/0 :: () -> 'done'). --spec(polite_pause/1 :: (non_neg_integer()) -> 'done'). --spec(die/1 :: - (rabbit_framing:amqp_exception()) -> channel_or_connection_exit()). - --spec(quit/1 :: (integer()) -> no_return()). - --spec(frame_error/2 :: (rabbit_framing:amqp_method_name(), binary()) - -> rabbit_types:connection_exit()). --spec(amqp_error/4 :: +-type ok_or_error() :: rabbit_types:ok_or_error(any()). +-type thunk(T) :: fun(() -> T). +-type resource_name() :: binary(). +-type channel_or_connection_exit() + :: rabbit_types:channel_exit() | rabbit_types:connection_exit(). +-type digraph_label() :: term(). +-type graph_vertex_fun() :: + fun (({atom(), [term()]}) -> [{digraph:vertex(), digraph_label()}]). +-type graph_edge_fun() :: + fun (({atom(), [term()]}) -> [{digraph:vertex(), digraph:vertex()}]). +-type tref() :: {'erlang', reference()} | {timer, timer:tref()}. + +-spec method_record_type(rabbit_framing:amqp_method_record()) -> + rabbit_framing:amqp_method_name(). +-spec polite_pause() -> 'done'. +-spec polite_pause(non_neg_integer()) -> 'done'. +-spec die(rabbit_framing:amqp_exception()) -> channel_or_connection_exit(). + +-spec quit(integer()) -> no_return(). + +-spec frame_error(rabbit_framing:amqp_method_name(), binary()) -> + rabbit_types:connection_exit(). +-spec amqp_error (rabbit_framing:amqp_exception(), string(), [any()], - rabbit_framing:amqp_method_name()) - -> rabbit_types:amqp_error()). --spec(protocol_error/3 :: (rabbit_framing:amqp_exception(), string(), [any()]) - -> channel_or_connection_exit()). --spec(protocol_error/4 :: + rabbit_framing:amqp_method_name()) -> + rabbit_types:amqp_error(). +-spec protocol_error(rabbit_framing:amqp_exception(), string(), [any()]) -> + channel_or_connection_exit(). +-spec protocol_error (rabbit_framing:amqp_exception(), string(), [any()], - rabbit_framing:amqp_method_name()) -> channel_or_connection_exit()). --spec(protocol_error/1 :: - (rabbit_types:amqp_error()) -> channel_or_connection_exit()). --spec(not_found/1 :: (rabbit_types:r(atom())) -> rabbit_types:channel_exit()). --spec(absent/2 :: (rabbit_types:amqqueue(), rabbit_amqqueue:absent_reason()) - -> rabbit_types:channel_exit()). --spec(type_class/1 :: (rabbit_framing:amqp_field_type()) -> atom()). --spec(assert_args_equivalence/4 :: (rabbit_framing:amqp_table(), - rabbit_framing:amqp_table(), - rabbit_types:r(any()), [binary()]) -> - 'ok' | rabbit_types:connection_exit()). --spec(assert_field_equivalence/4 :: + rabbit_framing:amqp_method_name()) -> + channel_or_connection_exit(). +-spec protocol_error(rabbit_types:amqp_error()) -> + channel_or_connection_exit(). +-spec not_found(rabbit_types:r(atom())) -> rabbit_types:channel_exit(). +-spec absent(rabbit_types:amqqueue(), rabbit_amqqueue:absent_reason()) -> + rabbit_types:channel_exit(). +-spec type_class(rabbit_framing:amqp_field_type()) -> atom(). +-spec assert_args_equivalence + (rabbit_framing:amqp_table(), rabbit_framing:amqp_table(), + rabbit_types:r(any()), [binary()]) -> + 'ok' | rabbit_types:connection_exit(). +-spec assert_field_equivalence (any(), any(), rabbit_types:r(any()), atom() | binary()) -> - 'ok' | rabbit_types:connection_exit()). --spec(equivalence_fail/4 :: + 'ok' | rabbit_types:connection_exit(). +-spec equivalence_fail (any(), any(), rabbit_types:r(any()), atom() | binary()) -> - rabbit_types:connection_exit()). --spec(dirty_read/1 :: - ({atom(), any()}) -> rabbit_types:ok_or_error2(any(), 'not_found')). --spec(table_lookup/2 :: - (rabbit_framing:amqp_table(), binary()) - -> 'undefined' | {rabbit_framing:amqp_field_type(), any()}). --spec(set_table_value/4 :: - (rabbit_framing:amqp_table(), binary(), - rabbit_framing:amqp_field_type(), rabbit_framing:amqp_value()) - -> rabbit_framing:amqp_table()). --spec(r/2 :: (rabbit_types:vhost(), K) - -> rabbit_types:r3(rabbit_types:vhost(), K, '_') - when is_subtype(K, atom())). --spec(r/3 :: - (rabbit_types:vhost() | rabbit_types:r(atom()), K, resource_name()) - -> rabbit_types:r3(rabbit_types:vhost(), K, resource_name()) - when is_subtype(K, atom())). --spec(r_arg/4 :: + rabbit_types:connection_exit(). +-spec dirty_read({atom(), any()}) -> + rabbit_types:ok_or_error2(any(), 'not_found'). +-spec table_lookup(rabbit_framing:amqp_table(), binary()) -> + 'undefined' | {rabbit_framing:amqp_field_type(), any()}. +-spec set_table_value + (rabbit_framing:amqp_table(), binary(), rabbit_framing:amqp_field_type(), + rabbit_framing:amqp_value()) -> + rabbit_framing:amqp_table(). +-spec r(rabbit_types:vhost(), K) -> + rabbit_types:r3(rabbit_types:vhost(), K, '_') + when is_subtype(K, atom()). +-spec r(rabbit_types:vhost() | rabbit_types:r(atom()), K, resource_name()) -> + rabbit_types:r3(rabbit_types:vhost(), K, resource_name()) + when is_subtype(K, atom()). +-spec r_arg (rabbit_types:vhost() | rabbit_types:r(atom()), K, rabbit_framing:amqp_table(), binary()) -> - undefined | - rabbit_types:error( - {invalid_type, rabbit_framing:amqp_field_type()}) | - rabbit_types:r(K) when is_subtype(K, atom())). --spec(rs/1 :: (rabbit_types:r(atom())) -> string()). --spec(enable_cover/0 :: () -> ok_or_error()). --spec(start_cover/1 :: ([{string(), string()} | string()]) -> 'ok'). --spec(report_cover/0 :: () -> 'ok'). --spec(enable_cover/1 :: ([file:filename() | atom()]) -> ok_or_error()). --spec(report_cover/1 :: ([file:filename() | atom()]) -> 'ok'). --spec(throw_on_error/2 :: - (atom(), thunk(rabbit_types:error(any()) | {ok, A} | A)) -> A). --spec(with_exit_handler/2 :: (thunk(A), thunk(A)) -> A). --spec(is_abnormal_exit/1 :: (any()) -> boolean()). --spec(filter_exit_map/2 :: (fun ((A) -> B), [A]) -> [B]). --spec(with_user/2 :: (rabbit_types:username(), thunk(A)) -> A). --spec(with_user_and_vhost/3 :: - (rabbit_types:username(), rabbit_types:vhost(), thunk(A)) - -> A). --spec(execute_mnesia_transaction/1 :: (thunk(A)) -> A). --spec(execute_mnesia_transaction/2 :: - (thunk(A), fun ((A, boolean()) -> B)) -> B). --spec(execute_mnesia_tx_with_tail/1 :: - (thunk(fun ((boolean()) -> B))) -> B | (fun ((boolean()) -> B))). --spec(ensure_ok/2 :: (ok_or_error(), atom()) -> 'ok'). --spec(tcp_name/3 :: - (atom(), inet:ip_address(), rabbit_networking:ip_port()) - -> atom()). --spec(format_inet_error/1 :: (atom()) -> string()). --spec(upmap/2 :: (fun ((A) -> B), [A]) -> [B]). --spec(map_in_order/2 :: (fun ((A) -> B), [A]) -> [B]). --spec(table_filter/3:: (fun ((A) -> boolean()), fun ((A, boolean()) -> 'ok'), - atom()) -> [A]). --spec(dirty_read_all/1 :: (atom()) -> [any()]). --spec(dirty_foreach_key/2 :: (fun ((any()) -> any()), atom()) - -> 'ok' | 'aborted'). --spec(dirty_dump_log/1 :: (file:filename()) -> ok_or_error()). --spec(format/2 :: (string(), [any()]) -> string()). --spec(format_many/1 :: ([{string(), [any()]}]) -> string()). --spec(format_stderr/2 :: (string(), [any()]) -> 'ok'). --spec(unfold/2 :: (fun ((A) -> ({'true', B, A} | 'false')), A) -> {[B], A}). --spec(ceil/1 :: (number()) -> integer()). --spec(queue_fold/3 :: (fun ((any(), B) -> B), B, queue:queue()) -> B). --spec(sort_field_table/1 :: - (rabbit_framing:amqp_table()) -> rabbit_framing:amqp_table()). --spec(pid_to_string/1 :: (pid()) -> string()). --spec(string_to_pid/1 :: (string()) -> pid()). --spec(pid_change_node/2 :: (pid(), node()) -> pid()). --spec(node_to_fake_pid/1 :: (atom()) -> pid()). --spec(version_compare/2 :: (string(), string()) -> 'lt' | 'eq' | 'gt'). --spec(version_compare/3 :: - (string(), string(), ('lt' | 'lte' | 'eq' | 'gte' | 'gt')) - -> boolean()). --spec(version_minor_equivalent/2 :: (string(), string()) -> boolean()). --spec(dict_cons/3 :: (any(), any(), dict:dict()) -> dict:dict()). --spec(orddict_cons/3 :: (any(), any(), orddict:orddict()) -> orddict:orddict()). --spec(gb_trees_cons/3 :: (any(), any(), gb_trees:tree()) -> gb_trees:tree()). --spec(gb_trees_fold/3 :: (fun ((any(), any(), A) -> A), A, gb_trees:tree()) - -> A). --spec(gb_trees_foreach/2 :: - (fun ((any(), any()) -> any()), gb_trees:tree()) -> 'ok'). --spec(all_module_attributes/1 :: - (atom()) -> [{atom(), atom(), [term()]}]). --spec(build_acyclic_graph/3 :: - (graph_vertex_fun(), graph_edge_fun(), [{atom(), [term()]}]) - -> rabbit_types:ok_or_error2(digraph:graph(), - {'vertex', 'duplicate', digraph:vertex()} | - {'edge', ({bad_vertex, digraph:vertex()} | - {bad_edge, [digraph:vertex()]}), - digraph:vertex(), digraph:vertex()})). --spec(const/1 :: (A) -> thunk(A)). --spec(ntoa/1 :: (inet:ip_address()) -> string()). --spec(ntoab/1 :: (inet:ip_address()) -> string()). --spec(is_process_alive/1 :: (pid()) -> boolean()). --spec(pget/2 :: (term(), [term()]) -> term()). --spec(pget/3 :: (term(), [term()], term()) -> term()). --spec(pget_or_die/2 :: (term(), [term()]) -> term() | no_return()). --spec(pmerge/3 :: (term(), term(), [term()]) -> [term()]). --spec(plmerge/2 :: ([term()], [term()]) -> [term()]). --spec(pset/3 :: (term(), term(), [term()]) -> [term()]). --spec(format_message_queue/2 :: (any(), priority_queue:q()) -> term()). --spec(append_rpc_all_nodes/4 :: ([node()], atom(), atom(), [any()]) -> [any()]). --spec(os_cmd/1 :: (string()) -> string()). --spec(is_os_process_alive/1 :: (non_neg_integer()) -> boolean()). --spec(gb_sets_difference/2 :: (gb_sets:set(), gb_sets:set()) -> gb_sets:set()). --spec(version/0 :: () -> string()). --spec(otp_release/0 :: () -> string()). --spec(which_applications/0 :: () -> [{atom(), string(), string()}]). --spec(sequence_error/1 :: ([({'error', any()} | any())]) - -> {'error', any()} | any()). --spec(json_encode/1 :: (any()) -> {'ok', string()} | {'error', any()}). --spec(json_decode/1 :: (string()) -> {'ok', any()} | 'error'). --spec(json_to_term/1 :: (any()) -> any()). --spec(term_to_json/1 :: (any()) -> any()). --spec(check_expiry/1 :: (integer()) -> rabbit_types:ok_or_error(any())). --spec(base64url/1 :: (binary()) -> string()). --spec(interval_operation/5 :: - ({atom(), atom(), any()}, float(), non_neg_integer(), non_neg_integer(), non_neg_integer()) - -> {any(), non_neg_integer()}). --spec(ensure_timer/4 :: (A, non_neg_integer(), non_neg_integer(), any()) -> A). --spec(stop_timer/2 :: (A, non_neg_integer()) -> A). --spec(send_after/3 :: (non_neg_integer(), pid(), any()) -> tref()). --spec(cancel_timer/1 :: (tref()) -> 'ok'). --spec(get_parent/0 :: () -> pid()). --spec(store_proc_name/2 :: (atom(), rabbit_types:proc_name()) -> ok). --spec(store_proc_name/1 :: (rabbit_types:proc_type_and_name()) -> ok). --spec(moving_average/4 :: (float(), float(), float(), float() | 'undefined') - -> float()). --spec(get_env/3 :: (atom(), atom(), term()) -> term()). --spec(get_channel_operation_timeout/0 :: () -> non_neg_integer()). --spec(random/1 :: (non_neg_integer()) -> non_neg_integer()). --spec(rpc_call/4 :: (node(), atom(), atom(), [any()]) -> any()). --spec(rpc_call/5 :: (node(), atom(), atom(), [any()], number()) -> any()). --spec(rpc_call/7 :: (node(), atom(), atom(), [any()], reference(), pid(), - number()) -> any()). --spec(report_default_thread_pool_size/0 :: () -> 'ok'). - --endif. + undefined | + rabbit_types:error( + {invalid_type, rabbit_framing:amqp_field_type()}) | + rabbit_types:r(K) when is_subtype(K, atom()). +-spec rs(rabbit_types:r(atom())) -> string(). +-spec enable_cover() -> ok_or_error(). +-spec start_cover([{string(), string()} | string()]) -> 'ok'. +-spec report_cover() -> 'ok'. +-spec enable_cover([file:filename() | atom()]) -> ok_or_error(). +-spec report_cover([file:filename() | atom()]) -> 'ok'. +-spec throw_on_error + (atom(), thunk(rabbit_types:error(any()) | {ok, A} | A)) -> A. +-spec with_exit_handler(thunk(A), thunk(A)) -> A. +-spec is_abnormal_exit(any()) -> boolean(). +-spec filter_exit_map(fun ((A) -> B), [A]) -> [B]. +-spec with_user(rabbit_types:username(), thunk(A)) -> A. +-spec with_user_and_vhost + (rabbit_types:username(), rabbit_types:vhost(), thunk(A)) -> A. +-spec execute_mnesia_transaction(thunk(A)) -> A. +-spec execute_mnesia_transaction(thunk(A), fun ((A, boolean()) -> B)) -> B. +-spec execute_mnesia_tx_with_tail + (thunk(fun ((boolean()) -> B))) -> B | (fun ((boolean()) -> B)). +-spec ensure_ok(ok_or_error(), atom()) -> 'ok'. +-spec tcp_name(atom(), inet:ip_address(), rabbit_networking:ip_port()) -> + atom(). +-spec format_inet_error(atom()) -> string(). +-spec upmap(fun ((A) -> B), [A]) -> [B]. +-spec map_in_order(fun ((A) -> B), [A]) -> [B]. +-spec table_filter + (fun ((A) -> boolean()), fun ((A, boolean()) -> 'ok'), atom()) -> [A]. +-spec dirty_read_all(atom()) -> [any()]. +-spec dirty_foreach_key(fun ((any()) -> any()), atom()) -> + 'ok' | 'aborted'. +-spec dirty_dump_log(file:filename()) -> ok_or_error(). +-spec format(string(), [any()]) -> string(). +-spec format_many([{string(), [any()]}]) -> string(). +-spec format_stderr(string(), [any()]) -> 'ok'. +-spec unfold (fun ((A) -> ({'true', B, A} | 'false')), A) -> {[B], A}. +-spec ceil(number()) -> integer(). +-spec queue_fold(fun ((any(), B) -> B), B, queue:queue()) -> B. +-spec sort_field_table(rabbit_framing:amqp_table()) -> + rabbit_framing:amqp_table(). +-spec pid_to_string(pid()) -> string(). +-spec string_to_pid(string()) -> pid(). +-spec pid_change_node(pid(), node()) -> pid(). +-spec node_to_fake_pid(atom()) -> pid(). +-spec version_compare(string(), string()) -> 'lt' | 'eq' | 'gt'. +-spec version_compare + (string(), string(), ('lt' | 'lte' | 'eq' | 'gte' | 'gt')) -> boolean(). +-spec version_minor_equivalent(string(), string()) -> boolean(). +-spec dict_cons(any(), any(), dict:dict()) -> dict:dict(). +-spec orddict_cons(any(), any(), orddict:orddict()) -> orddict:orddict(). +-spec gb_trees_cons(any(), any(), gb_trees:tree()) -> gb_trees:tree(). +-spec gb_trees_fold(fun ((any(), any(), A) -> A), A, gb_trees:tree()) -> A. +-spec gb_trees_foreach(fun ((any(), any()) -> any()), gb_trees:tree()) -> + 'ok'. +-spec all_module_attributes(atom()) -> [{atom(), atom(), [term()]}]. +-spec build_acyclic_graph + (graph_vertex_fun(), graph_edge_fun(), [{atom(), [term()]}]) -> + rabbit_types:ok_or_error2( + digraph:graph(), + {'vertex', 'duplicate', digraph:vertex()} | + {'edge', + ({bad_vertex, digraph:vertex()} | + {bad_edge, [digraph:vertex()]}), + digraph:vertex(), digraph:vertex()}). +-spec const(A) -> thunk(A). +-spec ntoa(inet:ip_address()) -> string(). +-spec ntoab(inet:ip_address()) -> string(). +-spec is_process_alive(pid()) -> boolean(). +-spec pget(term(), [term()]) -> term(). +-spec pget(term(), [term()], term()) -> term(). +-spec pget_or_die(term(), [term()]) -> term() | no_return(). +-spec pmerge(term(), term(), [term()]) -> [term()]. +-spec plmerge([term()], [term()]) -> [term()]. +-spec pset(term(), term(), [term()]) -> [term()]. +-spec format_message_queue(any(), priority_queue:q()) -> term(). +-spec append_rpc_all_nodes([node()], atom(), atom(), [any()]) -> [any()]. +-spec os_cmd(string()) -> string(). +-spec is_os_process_alive(non_neg_integer()) -> boolean(). +-spec gb_sets_difference(gb_sets:set(), gb_sets:set()) -> gb_sets:set(). +-spec version() -> string(). +-spec otp_release() -> string(). +-spec which_applications() -> [{atom(), string(), string()}]. +-spec sequence_error([({'error', any()} | any())]) -> + {'error', any()} | any(). +-spec json_encode(any()) -> {'ok', string()} | {'error', any()}. +-spec json_decode(string()) -> {'ok', any()} | 'error'. +-spec json_to_term(any()) -> any(). +-spec term_to_json(any()) -> any(). +-spec check_expiry(integer()) -> rabbit_types:ok_or_error(any()). +-spec base64url(binary()) -> string(). +-spec interval_operation + ({atom(), atom(), any()}, float(), non_neg_integer(), non_neg_integer(), + non_neg_integer()) -> + {any(), non_neg_integer()}. +-spec ensure_timer(A, non_neg_integer(), non_neg_integer(), any()) -> A. +-spec stop_timer(A, non_neg_integer()) -> A. +-spec send_after(non_neg_integer(), pid(), any()) -> tref(). +-spec cancel_timer(tref()) -> 'ok'. +-spec get_parent() -> pid(). +-spec store_proc_name(atom(), rabbit_types:proc_name()) -> ok. +-spec store_proc_name(rabbit_types:proc_type_and_name()) -> ok. +-spec moving_average(float(), float(), float(), float() | 'undefined') -> + float(). +-spec get_env(atom(), atom(), term()) -> term(). +-spec get_channel_operation_timeout() -> non_neg_integer(). +-spec random(non_neg_integer()) -> non_neg_integer(). +-spec rpc_call(node(), atom(), atom(), [any()]) -> any(). +-spec rpc_call(node(), atom(), atom(), [any()], number()) -> any(). +-spec rpc_call + (node(), atom(), atom(), [any()], reference(), pid(), number()) -> any(). +-spec report_default_thread_pool_size() -> 'ok'. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_msg_store_index.erl b/deps/rabbit_common/src/rabbit_msg_store_index.erl index b230ca880a..b33cd4f81d 100644 --- a/deps/rabbit_common/src/rabbit_msg_store_index.erl +++ b/deps/rabbit_common/src/rabbit_msg_store_index.erl @@ -18,8 +18,6 @@ -include("rabbit_msg_store.hrl"). --ifdef(use_specs). - -type(dir() :: any()). -type(index_state() :: any()). -type(keyvalue() :: any()). @@ -38,22 +36,3 @@ -callback delete_object(keyvalue(), index_state()) -> 'ok'. -callback delete_by_file(fieldvalue(), index_state()) -> 'ok'. -callback terminate(index_state()) -> any(). - --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{new, 1}, - {recover, 1}, - {lookup, 2}, - {insert, 2}, - {update, 2}, - {update_fields, 3}, - {delete, 2}, - {delete_by_file, 2}, - {terminate, 1}]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_net.erl b/deps/rabbit_common/src/rabbit_net.erl index e77f2ab092..792eb55fb8 100644 --- a/deps/rabbit_common/src/rabbit_net.erl +++ b/deps/rabbit_common/src/rabbit_net.erl @@ -34,63 +34,56 @@ %%--------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([socket/0]). --type(stat_option() :: +-type stat_option() :: 'recv_cnt' | 'recv_max' | 'recv_avg' | 'recv_oct' | 'recv_dvi' | - 'send_cnt' | 'send_max' | 'send_avg' | 'send_oct' | 'send_pend'). --type(ok_val_or_error(A) :: rabbit_types:ok_or_error2(A, any())). --type(ok_or_any_error() :: rabbit_types:ok_or_error(any())). --type(socket() :: port() | ssl:sslsocket()). --type(opts() :: [{atom(), any()} | - {raw, non_neg_integer(), non_neg_integer(), binary()}]). --type(host_or_ip() :: binary() | inet:ip_address()). --spec(is_ssl/1 :: (socket()) -> boolean()). --spec(ssl_info/1 :: (socket()) - -> 'nossl' | ok_val_or_error( - [{atom(), any()}])). --spec(controlling_process/2 :: (socket(), pid()) -> ok_or_any_error()). --spec(getstat/2 :: - (socket(), [stat_option()]) - -> ok_val_or_error([{stat_option(), integer()}])). --spec(recv/1 :: (socket()) -> - {'data', [char()] | binary()} | 'closed' | - rabbit_types:error(any()) | {'other', any()}). --spec(sync_recv/2 :: (socket(), integer()) -> rabbit_types:ok(binary()) | - rabbit_types:error(any())). --spec(async_recv/3 :: - (socket(), integer(), timeout()) -> rabbit_types:ok(any())). --spec(port_command/2 :: (socket(), iolist()) -> 'true'). --spec(getopts/2 :: (socket(), [atom() | {raw, - non_neg_integer(), - non_neg_integer(), - non_neg_integer() | binary()}]) - -> ok_val_or_error(opts())). --spec(setopts/2 :: (socket(), opts()) -> ok_or_any_error()). --spec(send/2 :: (socket(), binary() | iolist()) -> ok_or_any_error()). --spec(close/1 :: (socket()) -> ok_or_any_error()). --spec(fast_close/1 :: (socket()) -> ok_or_any_error()). --spec(sockname/1 :: - (socket()) - -> ok_val_or_error({inet:ip_address(), rabbit_networking:ip_port()})). --spec(peername/1 :: - (socket()) - -> ok_val_or_error({inet:ip_address(), rabbit_networking:ip_port()})). --spec(peercert/1 :: - (socket()) - -> 'nossl' | ok_val_or_error(rabbit_ssl:certificate())). --spec(connection_string/2 :: - (socket(), 'inbound' | 'outbound') -> ok_val_or_error(string())). --spec(socket_ends/2 :: - (socket(), 'inbound' | 'outbound') - -> ok_val_or_error({host_or_ip(), rabbit_networking:ip_port(), - host_or_ip(), rabbit_networking:ip_port()})). --spec(is_loopback/1 :: (socket() | inet:ip_address()) -> boolean()). --spec(accept_ack/2 :: (any(), socket()) -> ok). - --endif. + 'send_cnt' | 'send_max' | 'send_avg' | 'send_oct' | 'send_pend'. +-type ok_val_or_error(A) :: rabbit_types:ok_or_error2(A, any()). +-type ok_or_any_error() :: rabbit_types:ok_or_error(any()). +-type socket() :: port() | ssl:sslsocket(). +-type opts() :: [{atom(), any()} | + {raw, non_neg_integer(), non_neg_integer(), binary()}]. +-type host_or_ip() :: binary() | inet:ip_address(). +-spec is_ssl(socket()) -> boolean(). +-spec ssl_info(socket()) -> 'nossl' | ok_val_or_error([{atom(), any()}]). +-spec controlling_process(socket(), pid()) -> ok_or_any_error(). +-spec getstat(socket(), [stat_option()]) -> + ok_val_or_error([{stat_option(), integer()}]). +-spec recv(socket()) -> + {'data', [char()] | binary()} | + 'closed' | + rabbit_types:error(any()) | + {'other', any()}. +-spec sync_recv(socket(), integer()) -> + rabbit_types:ok(binary()) | + rabbit_types:error(any()). +-spec async_recv(socket(), integer(), timeout()) -> + rabbit_types:ok(any()). +-spec port_command(socket(), iolist()) -> 'true'. +-spec getopts + (socket(), + [atom() | + {raw, non_neg_integer(), non_neg_integer(), + non_neg_integer() | binary()}]) -> + ok_val_or_error(opts()). +-spec setopts(socket(), opts()) -> ok_or_any_error(). +-spec send(socket(), binary() | iolist()) -> ok_or_any_error(). +-spec close(socket()) -> ok_or_any_error(). +-spec fast_close(socket()) -> ok_or_any_error(). +-spec sockname(socket()) -> + ok_val_or_error({inet:ip_address(), rabbit_networking:ip_port()}). +-spec peername(socket()) -> + ok_val_or_error({inet:ip_address(), rabbit_networking:ip_port()}). +-spec peercert(socket()) -> + 'nossl' | ok_val_or_error(rabbit_ssl:certificate()). +-spec connection_string(socket(), 'inbound' | 'outbound') -> + ok_val_or_error(string()). +-spec socket_ends(socket(), 'inbound' | 'outbound') -> + ok_val_or_error({host_or_ip(), rabbit_networking:ip_port(), + host_or_ip(), rabbit_networking:ip_port()}). +-spec is_loopback(socket() | inet:ip_address()) -> boolean(). +-spec accept_ack(any(), socket()) -> ok. %%--------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_networking.erl b/deps/rabbit_common/src/rabbit_networking.erl index 67733689a4..5bf30ff5e5 100644 --- a/deps/rabbit_common/src/rabbit_networking.erl +++ b/deps/rabbit_common/src/rabbit_networking.erl @@ -58,72 +58,66 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -export_type([ip_port/0, hostname/0]). --type(hostname() :: inet:hostname()). --type(ip_port() :: inet:port_number()). +-type hostname() :: inet:hostname(). +-type ip_port() :: inet:port_number(). --type(family() :: atom()). --type(listener_config() :: ip_port() | +-type family() :: atom(). +-type listener_config() :: ip_port() | {hostname(), ip_port()} | - {hostname(), ip_port(), family()}). --type(address() :: {inet:ip_address(), ip_port(), family()}). --type(name_prefix() :: atom()). --type(protocol() :: atom()). --type(label() :: string()). - --spec(start_tcp_listener/2 :: (listener_config(), integer()) -> 'ok'). --spec(start_ssl_listener/3 :: - (listener_config(), rabbit_types:infos(), integer()) -> 'ok'). --spec(stop_tcp_listener/1 :: (listener_config()) -> 'ok'). --spec(active_listeners/0 :: () -> [rabbit_types:listener()]). --spec(node_listeners/1 :: (node()) -> [rabbit_types:listener()]). --spec(register_connection/1 :: (pid()) -> ok). --spec(unregister_connection/1 :: (pid()) -> ok). --spec(connections/0 :: () -> [rabbit_types:connection()]). --spec(connections_local/0 :: () -> [rabbit_types:connection()]). --spec(connection_info_keys/0 :: () -> rabbit_types:info_keys()). --spec(connection_info/1 :: - (rabbit_types:connection()) -> rabbit_types:infos()). --spec(connection_info/2 :: - (rabbit_types:connection(), rabbit_types:info_keys()) - -> rabbit_types:infos()). --spec(connection_info_all/0 :: () -> [rabbit_types:infos()]). --spec(connection_info_all/1 :: - (rabbit_types:info_keys()) -> [rabbit_types:infos()]). --spec(connection_info_all/3 :: - (rabbit_types:info_keys(), reference(), pid()) -> 'ok'). --spec(close_connection/2 :: (pid(), string()) -> 'ok'). --spec(force_connection_event_refresh/1 :: (reference()) -> 'ok'). - --spec(on_node_down/1 :: (node()) -> 'ok'). --spec(tcp_listener_addresses/1 :: (listener_config()) -> [address()]). --spec(tcp_listener_spec/9 :: - (name_prefix(), address(), [gen_tcp:listen_option()], module(), module(), protocol(), any(), - non_neg_integer(), label()) -> supervisor:child_spec()). --spec(ensure_ssl/0 :: () -> rabbit_types:infos()). --spec(fix_ssl_options/1 :: (rabbit_types:infos()) -> rabbit_types:infos()). --spec(poodle_check/1 :: (atom()) -> 'ok' | 'danger'). - --spec(boot/0 :: () -> 'ok'). --spec(tcp_listener_started/3 :: - (_, + {hostname(), ip_port(), family()}. +-type address() :: {inet:ip_address(), ip_port(), family()}. +-type name_prefix() :: atom(). +-type protocol() :: atom(). +-type label() :: string(). + +-spec start_tcp_listener(listener_config(), integer()) -> 'ok'. +-spec start_ssl_listener + (listener_config(), rabbit_types:infos(), integer()) -> 'ok'. +-spec stop_tcp_listener(listener_config()) -> 'ok'. +-spec active_listeners() -> [rabbit_types:listener()]. +-spec node_listeners(node()) -> [rabbit_types:listener()]. +-spec register_connection(pid()) -> ok. +-spec unregister_connection(pid()) -> ok. +-spec connections() -> [rabbit_types:connection()]. +-spec connections_local() -> [rabbit_types:connection()]. +-spec connection_info_keys() -> rabbit_types:info_keys(). +-spec connection_info(rabbit_types:connection()) -> rabbit_types:infos(). +-spec connection_info(rabbit_types:connection(), rabbit_types:info_keys()) -> + rabbit_types:infos(). +-spec connection_info_all() -> [rabbit_types:infos()]. +-spec connection_info_all(rabbit_types:info_keys()) -> + [rabbit_types:infos()]. +-spec connection_info_all(rabbit_types:info_keys(), reference(), pid()) -> + 'ok'. +-spec close_connection(pid(), string()) -> 'ok'. +-spec force_connection_event_refresh(reference()) -> 'ok'. + +-spec on_node_down(node()) -> 'ok'. +-spec tcp_listener_addresses(listener_config()) -> [address()]. +-spec tcp_listener_spec + (name_prefix(), address(), [gen_tcp:listen_option()], module(), module(), + protocol(), any(), non_neg_integer(), label()) -> + supervisor:child_spec(). +-spec ensure_ssl() -> rabbit_types:infos(). +-spec fix_ssl_options(rabbit_types:infos()) -> rabbit_types:infos(). +-spec poodle_check(atom()) -> 'ok' | 'danger'. + +-spec boot() -> 'ok'. +-spec tcp_listener_started + (_, string() | - {byte(),byte(),byte(),byte()} | - {char(),char(),char(),char(),char(),char(),char(),char()}, - _) -> - 'ok'). --spec(tcp_listener_stopped/3 :: - (_, + {byte(),byte(),byte(),byte()} | + {char(),char(),char(),char(),char(),char(),char(),char()}, _) -> + 'ok'. +-spec tcp_listener_stopped + (_, string() | - {byte(),byte(),byte(),byte()} | - {char(),char(),char(),char(),char(),char(),char(),char()}, - _) -> - 'ok'). - --endif. + {byte(),byte(),byte(),byte()} | + {char(),char(),char(),char(),char(),char(),char(),char()}, + _) -> + 'ok'. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_nodes.erl b/deps/rabbit_common/src/rabbit_nodes.erl index 8766fd2401..70a5355d9f 100644 --- a/deps/rabbit_common/src/rabbit_nodes.erl +++ b/deps/rabbit_common/src/rabbit_nodes.erl @@ -31,22 +31,18 @@ %% Specs %%---------------------------------------------------------------------------- --ifdef(use_specs). - --spec(names/1 :: (string()) -> rabbit_types:ok_or_error2( - [{string(), integer()}], term())). --spec(diagnostics/1 :: ([node()]) -> string()). --spec(make/1 :: ({string(), string()} | string()) -> node()). --spec(parts/1 :: (node() | string()) -> {string(), string()}). --spec(cookie_hash/0 :: () -> string()). --spec(is_running/2 :: (node(), atom()) -> boolean()). --spec(is_process_running/2 :: (node(), atom()) -> boolean()). --spec(cluster_name/0 :: () -> binary()). --spec(set_cluster_name/1 :: (binary()) -> 'ok'). --spec(ensure_epmd/0 :: () -> 'ok'). --spec(all_running/0 :: () -> [node()]). - --endif. +-spec names(string()) -> + rabbit_types:ok_or_error2([{string(), integer()}], term()). +-spec diagnostics([node()]) -> string(). +-spec make({string(), string()} | string()) -> node(). +-spec parts(node() | string()) -> {string(), string()}. +-spec cookie_hash() -> string(). +-spec is_running(node(), atom()) -> boolean(). +-spec is_process_running(node(), atom()) -> boolean(). +-spec cluster_name() -> binary(). +-spec set_cluster_name(binary()) -> 'ok'. +-spec ensure_epmd() -> 'ok'. +-spec all_running() -> [node()]. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_password_hashing.erl b/deps/rabbit_common/src/rabbit_password_hashing.erl index 54d2535ea5..fd2ba7027e 100644 --- a/deps/rabbit_common/src/rabbit_password_hashing.erl +++ b/deps/rabbit_common/src/rabbit_password_hashing.erl @@ -17,17 +17,4 @@ -module(rabbit_password_hashing). -include("rabbit.hrl"). --ifdef(use_specs). - -callback hash(rabbit_types:password()) -> rabbit_types:password_hash(). - --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{hash, 1}]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_policy_validator.erl b/deps/rabbit_common/src/rabbit_policy_validator.erl index bd8906088e..110a26c9f9 100644 --- a/deps/rabbit_common/src/rabbit_policy_validator.erl +++ b/deps/rabbit_common/src/rabbit_policy_validator.erl @@ -16,24 +16,9 @@ -module(rabbit_policy_validator). --ifdef(use_specs). - -export_type([validate_results/0]). -type(validate_results() :: 'ok' | {error, string(), [term()]} | [validate_results()]). -callback validate_policy([{binary(), term()}]) -> validate_results(). - --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [ - {validate_policy, 1} - ]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_queue_collector.erl b/deps/rabbit_common/src/rabbit_queue_collector.erl index f6677cb888..82a891a03e 100644 --- a/deps/rabbit_common/src/rabbit_queue_collector.erl +++ b/deps/rabbit_common/src/rabbit_queue_collector.erl @@ -32,14 +32,9 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - --spec(start_link/1 :: (rabbit_types:proc_name()) -> - rabbit_types:ok_pid_or_error()). --spec(register/2 :: (pid(), pid()) -> 'ok'). --spec(delete_all/1 :: (pid()) -> 'ok'). - --endif. +-spec start_link(rabbit_types:proc_name()) -> rabbit_types:ok_pid_or_error(). +-spec register(pid(), pid()) -> 'ok'. +-spec delete_all(pid()) -> 'ok'. %%---------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/rabbit_queue_decorator.erl b/deps/rabbit_common/src/rabbit_queue_decorator.erl index aab2812a07..ee24802727 100644 --- a/deps/rabbit_common/src/rabbit_queue_decorator.erl +++ b/deps/rabbit_common/src/rabbit_queue_decorator.erl @@ -22,8 +22,6 @@ %%---------------------------------------------------------------------------- --ifdef(use_specs). - -callback startup(rabbit_types:amqqueue()) -> 'ok'. -callback shutdown(rabbit_types:amqqueue()) -> 'ok'. @@ -37,18 +35,6 @@ -callback consumer_state_changed( rabbit_types:amqqueue(), integer(), boolean()) -> 'ok'. --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{startup, 1}, {shutdown, 1}, {policy_changed, 2}, - {active_for, 1}, {consumer_state_changed, 3}]; -behaviour_info(_Other) -> - undefined. - --endif. - %%---------------------------------------------------------------------------- select(Modules) -> diff --git a/deps/rabbit_common/src/rabbit_queue_master_locator.erl b/deps/rabbit_common/src/rabbit_queue_master_locator.erl index 0dc60183b8..21596ff0a9 100644 --- a/deps/rabbit_common/src/rabbit_queue_master_locator.erl +++ b/deps/rabbit_common/src/rabbit_queue_master_locator.erl @@ -16,19 +16,6 @@ -module(rabbit_queue_master_locator). --ifdef(use_specs). - -callback description() -> [proplists:property()]. -callback queue_master_location(rabbit_types:amqqueue()) -> {'ok', node()} | {'error', term()}. - --else. - --export([behaviour_info/1]). -behaviour_info(callbacks) -> - [{description, 0}, - {queue_master_location, 1}]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_reader.erl b/deps/rabbit_common/src/rabbit_reader.erl index 6da00a5e12..313dc6aa1e 100644 --- a/deps/rabbit_common/src/rabbit_reader.erl +++ b/deps/rabbit_common/src/rabbit_reader.erl @@ -180,33 +180,28 @@ %%-------------------------------------------------------------------------- --ifdef(use_specs). - --spec(start_link/3 :: (pid(), any(), rabbit_net:socket()) -> rabbit_types:ok(pid())). --spec(info_keys/0 :: () -> rabbit_types:info_keys()). --spec(info/1 :: (pid()) -> rabbit_types:infos()). --spec(info/2 :: (pid(), rabbit_types:info_keys()) -> rabbit_types:infos()). --spec(force_event_refresh/2 :: (pid(), reference()) -> 'ok'). --spec(shutdown/2 :: (pid(), string()) -> 'ok'). --type(resource_alert() :: {WasAlarmSetForNode :: boolean(), +-spec start_link(pid(), any(), rabbit_net:socket()) -> rabbit_types:ok(pid()). +-spec info_keys() -> rabbit_types:info_keys(). +-spec info(pid()) -> rabbit_types:infos(). +-spec info(pid(), rabbit_types:info_keys()) -> rabbit_types:infos(). +-spec force_event_refresh(pid(), reference()) -> 'ok'. +-spec shutdown(pid(), string()) -> 'ok'. +-type resource_alert() :: {WasAlarmSetForNode :: boolean(), IsThereAnyAlarmsWithSameSourceInTheCluster :: boolean(), - NodeForWhichAlarmWasSetOrCleared :: node()}). --spec(conserve_resources/3 :: (pid(), atom(), resource_alert()) -> 'ok'). --spec(server_properties/1 :: (rabbit_types:protocol()) -> - rabbit_framing:amqp_table()). + NodeForWhichAlarmWasSetOrCleared :: node()}. +-spec conserve_resources(pid(), atom(), resource_alert()) -> 'ok'. +-spec server_properties(rabbit_types:protocol()) -> + rabbit_framing:amqp_table(). %% These specs only exists to add no_return() to keep dialyzer happy --spec(init/4 :: (pid(), pid(), any(), rabbit_net:socket()) -> no_return()). --spec(start_connection/4 :: - (pid(), pid(), any(), rabbit_net:socket()) -> no_return()). +-spec init(pid(), pid(), any(), rabbit_net:socket()) -> no_return(). +-spec start_connection(pid(), pid(), any(), rabbit_net:socket()) -> + no_return(). --spec(mainloop/4 :: (_,[binary()], non_neg_integer(), #v1{}) -> any()). --spec(system_code_change/4 :: (_,_,_,_) -> {'ok',_}). --spec(system_continue/3 :: (_,_,{[binary()], non_neg_integer(), #v1{}}) -> - any()). --spec(system_terminate/4 :: (_,_,_,_) -> none()). - --endif. +-spec mainloop(_,[binary()], non_neg_integer(), #v1{}) -> any(). +-spec system_code_change(_,_,_,_) -> {'ok',_}. +-spec system_continue(_,_,{[binary()], non_neg_integer(), #v1{}}) -> any(). +-spec system_terminate(_,_,_,_) -> none(). %%-------------------------------------------------------------------------- @@ -1102,9 +1097,8 @@ refuse_connection(Sock, Exception, {A, B, C, D}) -> ok = inet_op(fun () -> rabbit_net:send(Sock, <<"AMQP",A,B,C,D>>) end), throw(Exception). --ifdef(use_specs). --spec(refuse_connection/2 :: (rabbit_net:socket(), any()) -> no_return()). --endif. +-spec refuse_connection(rabbit_net:socket(), any()) -> no_return(). + refuse_connection(Sock, Exception) -> refuse_connection(Sock, Exception, {0, 0, 9, 1}). @@ -1253,7 +1247,7 @@ validate_negotiated_integer_value(Field, Min, ClientValue) -> %% keep dialyzer happy -spec fail_negotiation(atom(), 'min' | 'max', integer(), integer()) -> - no_return(). + no_return(). fail_negotiation(Field, MinOrMax, ServerValue, ClientValue) -> {S1, S2} = case MinOrMax of min -> {lower, minimum}; @@ -1334,11 +1328,10 @@ auth_phase(Response, auth_state = none}} end. --ifdef(use_specs). --spec(auth_fail/5 :: +-spec auth_fail (rabbit_types:username() | none, string(), [any()], binary(), #v1{}) -> - no_return()). --endif. + no_return(). + auth_fail(Username, Msg, Args, AuthName, State = #v1{connection = #connection{protocol = Protocol, capabilities = Capabilities}}) -> @@ -1468,9 +1461,8 @@ emit_stats(State) -> ensure_stats_timer(State1). %% 1.0 stub --ifdef(use_specs). --spec(become_1_0/2 :: (non_neg_integer(), #v1{}) -> no_return()). --endif. +-spec become_1_0(non_neg_integer(), #v1{}) -> no_return(). + become_1_0(Id, State = #v1{sock = Sock}) -> case code:is_loaded(rabbit_amqp1_0_reader) of false -> refuse_connection(Sock, amqp1_0_plugin_not_enabled); diff --git a/deps/rabbit_common/src/rabbit_runtime_parameter.erl b/deps/rabbit_common/src/rabbit_runtime_parameter.erl index 4e360687ad..e287d2f2bb 100644 --- a/deps/rabbit_common/src/rabbit_runtime_parameter.erl +++ b/deps/rabbit_common/src/rabbit_runtime_parameter.erl @@ -16,8 +16,6 @@ -module(rabbit_runtime_parameter). --ifdef(use_specs). - -type(validate_results() :: 'ok' | {error, string(), [term()]} | [validate_results()]). @@ -25,18 +23,3 @@ term(), rabbit_types:user()) -> validate_results(). -callback notify(rabbit_types:vhost(), binary(), binary(), term()) -> 'ok'. -callback notify_clear(rabbit_types:vhost(), binary(), binary()) -> 'ok'. - --else. - --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [ - {validate, 5}, - {notify, 4}, - {notify_clear, 3} - ]; -behaviour_info(_Other) -> - undefined. - --endif. diff --git a/deps/rabbit_common/src/rabbit_types.erl b/deps/rabbit_common/src/rabbit_types.erl index 3dcb63cbb9..29a3ef92a1 100644 --- a/deps/rabbit_common/src/rabbit_types.erl +++ b/deps/rabbit_common/src/rabbit_types.erl @@ -18,8 +18,6 @@ -include("rabbit.hrl"). --ifdef(use_specs). - -export_type([maybe/1, info/0, infos/0, info_key/0, info_keys/0, message/0, msg_id/0, basic_message/0, delivery/0, content/0, decoded_content/0, undecoded_content/0, @@ -164,5 +162,3 @@ -type(proc_name() :: term()). -type(proc_type_and_name() :: {atom(), proc_name()}). - --endif. % use_specs diff --git a/deps/rabbit_common/src/rabbit_writer.erl b/deps/rabbit_common/src/rabbit_writer.erl index 3153a9642e..3884f1a1e9 100644 --- a/deps/rabbit_common/src/rabbit_writer.erl +++ b/deps/rabbit_common/src/rabbit_writer.erl @@ -72,67 +72,59 @@ %%--------------------------------------------------------------------------- --ifdef(use_specs). - --spec(start/6 :: +-spec start (rabbit_net:socket(), rabbit_channel:channel_number(), non_neg_integer(), rabbit_types:protocol(), pid(), - rabbit_types:proc_name()) - -> rabbit_types:ok(pid())). --spec(start_link/6 :: + rabbit_types:proc_name()) -> + rabbit_types:ok(pid()). +-spec start_link (rabbit_net:socket(), rabbit_channel:channel_number(), non_neg_integer(), rabbit_types:protocol(), pid(), - rabbit_types:proc_name()) - -> rabbit_types:ok(pid())). --spec(start/7 :: + rabbit_types:proc_name()) -> + rabbit_types:ok(pid()). +-spec start (rabbit_net:socket(), rabbit_channel:channel_number(), non_neg_integer(), rabbit_types:protocol(), pid(), - rabbit_types:proc_name(), boolean()) - -> rabbit_types:ok(pid())). --spec(start_link/7 :: + rabbit_types:proc_name(), boolean()) -> + rabbit_types:ok(pid()). +-spec start_link (rabbit_net:socket(), rabbit_channel:channel_number(), non_neg_integer(), rabbit_types:protocol(), pid(), - rabbit_types:proc_name(), boolean()) - -> rabbit_types:ok(pid())). - --spec(system_code_change/4 :: (_,_,_,_) -> {'ok',_}). --spec(system_continue/3 :: (_,_,#wstate{}) -> any()). --spec(system_terminate/4 :: (_,_,_,_) -> none()). - --spec(send_command/2 :: - (pid(), rabbit_framing:amqp_method_record()) -> 'ok'). --spec(send_command/3 :: - (pid(), rabbit_framing:amqp_method_record(), rabbit_types:content()) - -> 'ok'). --spec(send_command_sync/2 :: - (pid(), rabbit_framing:amqp_method_record()) -> 'ok'). --spec(send_command_sync/3 :: - (pid(), rabbit_framing:amqp_method_record(), rabbit_types:content()) - -> 'ok'). --spec(send_command_and_notify/4 :: - (pid(), pid(), pid(), rabbit_framing:amqp_method_record()) - -> 'ok'). --spec(send_command_and_notify/5 :: + rabbit_types:proc_name(), boolean()) -> + rabbit_types:ok(pid()). + +-spec system_code_change(_,_,_,_) -> {'ok',_}. +-spec system_continue(_,_,#wstate{}) -> any(). +-spec system_terminate(_,_,_,_) -> none(). + +-spec send_command(pid(), rabbit_framing:amqp_method_record()) -> 'ok'. +-spec send_command + (pid(), rabbit_framing:amqp_method_record(), rabbit_types:content()) -> + 'ok'. +-spec send_command_sync(pid(), rabbit_framing:amqp_method_record()) -> 'ok'. +-spec send_command_sync + (pid(), rabbit_framing:amqp_method_record(), rabbit_types:content()) -> + 'ok'. +-spec send_command_and_notify + (pid(), pid(), pid(), rabbit_framing:amqp_method_record()) -> 'ok'. +-spec send_command_and_notify (pid(), pid(), pid(), rabbit_framing:amqp_method_record(), - rabbit_types:content()) - -> 'ok'). --spec(send_command_flow/2 :: - (pid(), rabbit_framing:amqp_method_record()) -> 'ok'). --spec(send_command_flow/3 :: - (pid(), rabbit_framing:amqp_method_record(), rabbit_types:content()) - -> 'ok'). --spec(flush/1 :: (pid()) -> 'ok'). --spec(internal_send_command/4 :: + rabbit_types:content()) -> + 'ok'. +-spec send_command_flow(pid(), rabbit_framing:amqp_method_record()) -> 'ok'. +-spec send_command_flow + (pid(), rabbit_framing:amqp_method_record(), rabbit_types:content()) -> + 'ok'. +-spec flush(pid()) -> 'ok'. +-spec internal_send_command (rabbit_net:socket(), rabbit_channel:channel_number(), - rabbit_framing:amqp_method_record(), rabbit_types:protocol()) - -> 'ok'). --spec(internal_send_command/6 :: + rabbit_framing:amqp_method_record(), rabbit_types:protocol()) -> + 'ok'. +-spec internal_send_command (rabbit_net:socket(), rabbit_channel:channel_number(), rabbit_framing:amqp_method_record(), rabbit_types:content(), - non_neg_integer(), rabbit_types:protocol()) - -> 'ok'). - --endif. + non_neg_integer(), rabbit_types:protocol()) -> + 'ok'. %%--------------------------------------------------------------------------- diff --git a/deps/rabbit_common/src/supervisor2.erl b/deps/rabbit_common/src/supervisor2.erl index c8ffbb12ea..6dee9e6e43 100644 --- a/deps/rabbit_common/src/supervisor2.erl +++ b/deps/rabbit_common/src/supervisor2.erl @@ -75,13 +75,8 @@ terminate/2, code_change/3]). -export([try_again_restart/3]). -%%-------------------------------------------------------------------------- --ifdef(use_specs). -export_type([child_spec/0, startchild_ret/0, strategy/0, sup_name/0]). --endif. -%%-------------------------------------------------------------------------- --ifdef(use_specs). -type child() :: 'undefined' | pid(). -type child_id() :: term(). -type mfargs() :: {M :: module(), F :: atom(), A :: [term()] | undefined}. @@ -104,11 +99,9 @@ -type strategy() :: 'one_for_all' | 'one_for_one' | 'rest_for_one' | 'simple_one_for_one'. --endif. %%-------------------------------------------------------------------------- --ifdef(use_specs). -record(child, {% pid is undefined when child is not running pid = undefined :: child() | {restarting,pid()} | [pid()], name :: child_id(), @@ -118,22 +111,11 @@ child_type :: worker(), modules = [] :: modules()}). -type child_rec() :: #child{}. --else. --record(child, { - pid = undefined, - name, - mfargs, - restart_type, - shutdown, - child_type, - modules = []}). --endif. -define(DICT, dict). -define(SETS, sets). -define(SET, set). --ifdef(use_specs). -record(state, {name, strategy :: strategy(), children = [] :: [child_rec()], @@ -144,17 +126,6 @@ module, args}). -type state() :: #state{}. --else. --record(state, {name, - strategy, - children = [], - dynamics, - intensity, - period, - restarts = [], - module, - args}). --endif. -define(is_simple(State), State#state.strategy =:= simple_one_for_one). -define(is_permanent(R), ((R =:= permanent) orelse @@ -164,23 +135,13 @@ -define(is_explicit_restart(R), R == {shutdown, restart}). --ifdef(use_specs). -callback init(Args :: term()) -> {ok, {{RestartStrategy :: strategy(), MaxR :: non_neg_integer(), MaxT :: non_neg_integer()}, [ChildSpec :: child_spec()]}} | ignore. --else. --export([behaviour_info/1]). - -behaviour_info(callbacks) -> - [{init,1}]; -behaviour_info(_Other) -> - undefined. - --endif. -define(restarting(_Pid_), {restarting,_Pid_}). %%% --------------------------------------------------- @@ -188,7 +149,7 @@ behaviour_info(_Other) -> %%% Servers/processes should/could also be built using gen_server.erl. %%% SupName = {local, atom()} | {global, atom()}. %%% --------------------------------------------------- --ifdef(use_specs). + -type startlink_err() :: {'already_started', pid()} | {'shutdown', term()} | term(). @@ -198,23 +159,21 @@ behaviour_info(_Other) -> Module :: module(), Args :: term(). --endif. start_link(Mod, Args) -> gen_server:start_link(?MODULE, {self, Mod, Args}, []). - --ifdef(use_specs). + -spec start_link(SupName, Module, Args) -> startlink_ret() when SupName :: sup_name(), Module :: module(), Args :: term(). --endif. + start_link(SupName, Mod, Args) -> gen_server:start_link(SupName, ?MODULE, {SupName, Mod, Args}, []). - + %%% --------------------------------------------------- %%% Interface functions. %%% --------------------------------------------------- --ifdef(use_specs). + -type startchild_err() :: 'already_present' | {'already_started', Child :: child()} | term(). -type startchild_ret() :: {'ok', Child :: child()} @@ -224,11 +183,10 @@ start_link(SupName, Mod, Args) -> -spec start_child(SupRef, ChildSpec) -> startchild_ret() when SupRef :: sup_ref(), ChildSpec :: child_spec() | (List :: [term()]). --endif. + start_child(Supervisor, ChildSpec) -> call(Supervisor, {start_child, ChildSpec}). --ifdef(use_specs). -spec restart_child(SupRef, Id) -> Result when SupRef :: sup_ref(), Id :: child_id(), @@ -237,17 +195,16 @@ start_child(Supervisor, ChildSpec) -> | {'error', Error}, Error :: 'running' | 'restarting' | 'not_found' | 'simple_one_for_one' | term(). --endif. + restart_child(Supervisor, Name) -> call(Supervisor, {restart_child, Name}). --ifdef(use_specs). -spec delete_child(SupRef, Id) -> Result when SupRef :: sup_ref(), Id :: child_id(), Result :: 'ok' | {'error', Error}, Error :: 'running' | 'restarting' | 'not_found' | 'simple_one_for_one'. --endif. + delete_child(Supervisor, Name) -> call(Supervisor, {delete_child, Name}). @@ -257,28 +214,26 @@ delete_child(Supervisor, Name) -> %% Note that the child is *always* terminated in some %% way (maybe killed). %%----------------------------------------------------------------- --ifdef(use_specs). + -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'. --endif. + terminate_child(Supervisor, Name) -> call(Supervisor, {terminate_child, Name}). --ifdef(use_specs). -spec which_children(SupRef) -> [{Id,Child,Type,Modules}] when SupRef :: sup_ref(), Id :: child_id() | undefined, Child :: child() | 'restarting', Type :: worker(), Modules :: modules(). --endif. + which_children(Supervisor) -> call(Supervisor, which_children). --ifdef(use_specs). -spec count_children(SupRef) -> PropListOfCounts when SupRef :: sup_ref(), PropListOfCounts :: [Count], @@ -286,15 +241,14 @@ which_children(Supervisor) -> | {active, ActiveProcessCount :: non_neg_integer()} | {supervisors, ChildSupervisorCount :: non_neg_integer()} |{workers, ChildWorkerCount :: non_neg_integer()}. --endif. + count_children(Supervisor) -> call(Supervisor, count_children). --ifdef(use_specs). -spec find_child(Supervisor, Name) -> [pid()] when Supervisor :: sup_ref(), Name :: child_id(). --endif. + find_child(Supervisor, Name) -> [Pid || {Name1, Pid, _Type, _Modules} <- which_children(Supervisor), Name1 =:= Name]. @@ -302,11 +256,10 @@ find_child(Supervisor, Name) -> call(Supervisor, Req) -> gen_server:call(Supervisor, Req, infinity). --ifdef(use_specs). -spec check_childspecs(ChildSpecs) -> Result when ChildSpecs :: [child_spec()], Result :: 'ok' | {'error', Error :: term()}. --endif. + check_childspecs(ChildSpecs) when is_list(ChildSpecs) -> case check_startspec(ChildSpecs) of {ok, _} -> ok; @@ -316,12 +269,12 @@ check_childspecs(X) -> {error, {badarg, X}}. %%%----------------------------------------------------------------- %%% Called by timer:apply_after from restart/2 --ifdef(use_specs). + -spec try_again_restart(SupRef, Child, Reason) -> ok when SupRef :: sup_ref(), Child :: child_id() | pid(), Reason :: term(). --endif. + try_again_restart(Supervisor, Child, Reason) -> cast(Supervisor, {try_again_restart, Child, Reason}). @@ -329,11 +282,11 @@ cast(Supervisor, Req) -> gen_server:cast(Supervisor, Req). %%% --------------------------------------------------- -%%% +%%% %%% Initialize the supervisor. -%%% +%%% %%% --------------------------------------------------- --ifdef(use_specs). + -type init_sup_name() :: sup_name() | 'self'. -type stop_rsn() :: {'shutdown', term()} @@ -344,7 +297,7 @@ cast(Supervisor, Req) -> -spec init({init_sup_name(), module(), [term()]}) -> {'ok', state()} | 'ignore' | {'stop', stop_rsn()}. --endif. + init({SupName, Mod, Args}) -> process_flag(trap_exit, true), case Mod:init(Args) of @@ -448,14 +401,14 @@ do_start_child_i(M, F, A) -> end. %%% --------------------------------------------------- -%%% +%%% %%% Callback functions. -%%% +%%% %%% --------------------------------------------------- --ifdef(use_specs). + -type call() :: 'which_children' | 'count_children' | {_, _}. % XXX: refine -spec handle_call(call(), term(), state()) -> {'reply', term(), state()}. --endif. + handle_call({start_child, EArgs}, _From, State) when ?is_simple(State) -> Child = hd(State#state.children), #child{mfargs = {M, F, A}} = Child, @@ -638,10 +591,10 @@ count_child(#child{pid = Pid, child_type = supervisor}, %%% If a restart attempt failed, this message is sent via %%% timer:apply_after(0,...) in order to give gen_server the chance to %%% check it's inbox before trying again. --ifdef(use_specs). + -spec handle_cast({try_again_restart, child_id() | pid(), term()}, state()) -> {'noreply', state()} | {stop, shutdown, state()}. --endif. + handle_cast({try_again_restart,Pid,Reason}, #state{children=[Child]}=State) when ?is_simple(State) -> RT = Child#child.restart_type, @@ -667,10 +620,10 @@ handle_cast({try_again_restart,Name,Reason}, State) -> %% %% Take care of terminated children. %% --ifdef(use_specs). + -spec handle_info(term(), state()) -> {'noreply', state()} | {'stop', 'shutdown', state()}. --endif. + handle_info({'EXIT', Pid, Reason}, State) -> case restart_child(Pid, Reason, State) of {ok, State1} -> @@ -698,16 +651,16 @@ handle_info({delayed_restart, {RestartType, Reason, Child}}, State) -> %% this is important. handle_info(Msg, State) -> - error_logger:error_msg("Supervisor received unexpected message: ~p~n", + error_logger:error_msg("Supervisor received unexpected message: ~p~n", [Msg]), {noreply, State}. %% %% Terminate this server. %% --ifdef(use_specs). + -spec terminate(term(), state()) -> 'ok'. --endif. + terminate(_Reason, #state{children=[Child]} = State) when ?is_simple(State) -> terminate_dynamic_children(Child, dynamics_db(Child#child.restart_type, State#state.dynamics), @@ -724,10 +677,10 @@ terminate(_Reason, State) -> %% NOTE: This requires that the init function of the call-back module %% does not have any side effects. %% --ifdef(use_specs). + -spec code_change(term(), state(), term()) -> {'ok', state()} | {'error', term()}. --endif. + code_change(_, State, _) -> case (State#state.module):init(State#state.args) of {ok, {SupFlags, StartSpec}} -> @@ -795,7 +748,7 @@ update_chsp(OldCh, Children) -> NewC -> {ok, NewC} end. - + %%% --------------------------------------------------- %%% Start a new child. %%% --------------------------------------------------- @@ -1049,13 +1002,13 @@ do_terminate(Child, _SupName) -> Child#child{pid = undefined}. %%----------------------------------------------------------------- -%% Shutdowns a child. We must check the EXIT value +%% Shutdowns a child. We must check the EXIT value %% of the child, because it might have died with another reason than -%% the wanted. In that case we want to report the error. We put a -%% monitor on the child an check for the 'DOWN' message instead of -%% checking for the 'EXIT' message, because if we check the 'EXIT' -%% message a "naughty" child, who does unlink(Sup), could hang the -%% supervisor. +%% the wanted. In that case we want to report the error. We put a +%% monitor on the child an check for the 'DOWN' message instead of +%% checking for the 'EXIT' message, because if we check the 'EXIT' +%% message a "naughty" child, who does unlink(Sup), could hang the +%% supervisor. %% Returns: ok | {error, OtherReason} (this should be reported) %%----------------------------------------------------------------- shutdown(Pid, brutal_kill) -> @@ -1068,14 +1021,14 @@ shutdown(Pid, brutal_kill) -> {'DOWN', _MRef, process, Pid, OtherReason} -> {error, OtherReason} end; - {error, Reason} -> + {error, Reason} -> {error, Reason} end; shutdown(Pid, Time) -> case monitor_child(Pid) of ok -> exit(Pid, shutdown), %% Try to shutdown gracefully - receive + receive {'DOWN', _MRef, process, Pid, shutdown} -> ok; {'DOWN', _MRef, process, Pid, OtherReason} -> @@ -1087,14 +1040,14 @@ shutdown(Pid, Time) -> {error, OtherReason} end end; - {error, Reason} -> + {error, Reason} -> {error, Reason} end. %% Help function to shutdown/2 switches from link to monitor approach monitor_child(Pid) -> - - %% Do the monitor operation first so that if the child dies + + %% Do the monitor operation first so that if the child dies %% before the monitoring is done causing a 'DOWN'-message with %% reason noproc, we will get the real reason in the 'EXIT'-message %% unless a naughty child has already done unlink... @@ -1104,19 +1057,19 @@ monitor_child(Pid) -> receive %% If the child dies before the unlik we must empty %% the mail-box of the 'EXIT'-message and the 'DOWN'-message. - {'EXIT', Pid, Reason} -> - receive + {'EXIT', Pid, Reason} -> + receive {'DOWN', _, process, Pid, _} -> {error, Reason} end - after 0 -> + after 0 -> %% If a naughty child did unlink and the child dies before - %% monitor the result will be that shutdown/2 receives a + %% monitor the result will be that shutdown/2 receives a %% 'DOWN'-message with reason noproc. %% If the child should die after the unlink there %% will be a 'DOWN'-message with a correct reason - %% that will be handled in shutdown/2. - ok + %% that will be handled in shutdown/2. + ok end. @@ -1443,8 +1396,8 @@ validChildType(What) -> throw({invalid_child_type, What}). validName(_Name) -> true. -validFunc({M, F, A}) when is_atom(M), - is_atom(F), +validFunc({M, F, A}) when is_atom(M), + is_atom(F), is_list(A) -> true; validFunc(Func) -> throw({invalid_mfa, Func}). @@ -1462,7 +1415,7 @@ validDelay(Delay) when is_number(Delay), Delay >= 0 -> true; validDelay(What) -> throw({invalid_delay, What}). -validShutdown(Shutdown, _) +validShutdown(Shutdown, _) when is_integer(Shutdown), Shutdown > 0 -> true; validShutdown(infinity, _) -> true; validShutdown(brutal_kill, _) -> true; @@ -1488,7 +1441,7 @@ validMods(Mods) -> throw({invalid_modules, Mods}). %%% Returns: {ok, State'} | {terminate, State'} %%% ------------------------------------------------------ -add_restart(State) -> +add_restart(State) -> I = State#state.intensity, P = State#state.period, R = State#state.restarts, |