|
| 1 | +%% The contents of this file are subject to the Mozilla Public License |
| 2 | +%% Version 1.1 (the "License"); you may not use this file except in |
| 3 | +%% compliance with the License. You may obtain a copy of the License |
| 4 | +%% at https://www.mozilla.org/MPL/ |
| 5 | +%% |
| 6 | +%% Software distributed under the License is distributed on an "AS IS" |
| 7 | +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 8 | +%% the License for the specific language governing rights and |
| 9 | +%% limitations under the License. |
| 10 | +%% |
| 11 | +%% The Original Code is RabbitMQ. |
| 12 | +%% |
| 13 | +%% The Initial Developer of the Original Code is GoPivotal, Inc. |
| 14 | +%% Copyright (c) 2018-2019 Pivotal Software, Inc. All rights reserved. |
| 15 | +%% |
| 16 | + |
| 17 | +-include("amqqueue_v1.hrl"). |
| 18 | + |
| 19 | +-define(is_amqqueue(Q), |
| 20 | + (?is_amqqueue_v1(Q))). |
| 21 | + |
| 22 | +-define(amqqueue_is_auto_delete(Q), |
| 23 | + ((?is_amqqueue_v1(Q) andalso |
| 24 | + ?amqqueue_v1_field_auto_delete(Q) =:= true))). |
| 25 | + |
| 26 | +-define(amqqueue_is_durable(Q), |
| 27 | + ((?is_amqqueue_v1(Q) andalso |
| 28 | + ?amqqueue_v1_field_durable(Q) =:= true))). |
| 29 | + |
| 30 | +-define(amqqueue_exclusive_owner_is(Q, Owner), |
| 31 | + ((?is_amqqueue_v1(Q) andalso |
| 32 | + ?amqqueue_v1_field_exclusive_owner(Q) =:= Owner))). |
| 33 | + |
| 34 | +-define(amqqueue_exclusive_owner_is_pid(Q), |
| 35 | + ((?is_amqqueue_v1(Q) andalso |
| 36 | + is_pid(?amqqueue_v1_field_exclusive_owner(Q))))). |
| 37 | + |
| 38 | +-define(amqqueue_state_is(Q, State), |
| 39 | + ((?is_amqqueue_v1(Q) andalso |
| 40 | + ?amqqueue_v1_field_state(Q) =:= State))). |
| 41 | + |
| 42 | +-define(amqqueue_v1_type, classic). |
| 43 | + |
| 44 | +-define(amqqueue_is_classic(Q), |
| 45 | + (?is_amqqueue_v1(Q))). |
| 46 | + |
| 47 | +-define(amqqueue_is_quorum(Q), |
| 48 | + false). |
| 49 | + |
| 50 | +-define(amqqueue_has_valid_pid(Q), |
| 51 | + (?is_amqqueue_v1(Q) andalso |
| 52 | + is_pid(?amqqueue_v1_field_pid(Q)))). |
| 53 | + |
| 54 | +-define(amqqueue_pid_runs_on_local_node(Q), |
| 55 | + (?is_amqqueue_v1(Q) andalso |
| 56 | + node(?amqqueue_v1_field_pid(Q)) =:= node())). |
| 57 | + |
| 58 | +-define(amqqueue_pid_equals(Q, Pid), |
| 59 | + ((?is_amqqueue_v1(Q) andalso |
| 60 | + ?amqqueue_v1_field_pid(Q) =:= Pid))). |
| 61 | + |
| 62 | +-define(amqqueue_pids_are_equal(Q0, Q1), |
| 63 | + ((?is_amqqueue_v1(Q0) andalso ?is_amqqueue_v1(Q1) andalso |
| 64 | + ?amqqueue_v1_field_pid(Q0) =:= ?amqqueue_v1_field_pid(Q1)))). |
| 65 | + |
| 66 | +-define(amqqueue_field_name(Q), |
| 67 | + case ?is_amqqueue_v1(Q) of |
| 68 | + true -> ?amqqueue_v1_field_name(Q) |
| 69 | + end). |
| 70 | + |
| 71 | +-define(amqqueue_field_pid(Q), |
| 72 | + case ?is_amqqueue_v1(Q) of |
| 73 | + true -> ?amqqueue_v1_field_pid(Q) |
| 74 | + end). |
| 75 | + |
| 76 | +-define(amqqueue_v1_vhost(Q), element(2, ?amqqueue_v1_field_name(Q))). |
| 77 | + |
| 78 | +-define(amqqueue_vhost_equals(Q, VHost), |
| 79 | + ((?is_amqqueue_v1(Q) andalso |
| 80 | + ?amqqueue_v1_vhost(Q) =:= VHost))). |
| 81 | + |
| 82 | +-define(enable_quorum_queue_if_debug, noop). |
| 83 | + |
| 84 | +-define(try_mnesia_tx_or_upgrade_amqqueue_and_retry(Expr1, Expr2), |
| 85 | + try |
| 86 | + ?enable_quorum_queue_if_debug, |
| 87 | + Expr1 |
| 88 | + catch |
| 89 | + throw:{error, {bad_type, T}} when ?is_amqqueue(T) -> |
| 90 | + Expr2; |
| 91 | + throw:{aborted, {bad_type, T}} when ?is_amqqueue(T) -> |
| 92 | + Expr2 |
| 93 | + end). |
0 commit comments