|
| 1 | +%% This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +%% License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +%% file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | +%% |
| 5 | +%% Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. |
| 6 | +%% |
| 7 | + |
| 8 | +-module(rabbit_quorum_event_subscriber). |
| 9 | + |
| 10 | +-behaviour(gen_event). |
| 11 | + |
| 12 | +-export([init/1, handle_event/2, handle_call/2]). |
| 13 | +-export([register/0, unregister/0]). |
| 14 | + |
| 15 | +-include_lib("rabbit_common/include/rabbit.hrl"). |
| 16 | + |
| 17 | +-rabbit_boot_step({rabbit_quorum_event_subscriber, |
| 18 | + [{description, "quorum queue event subscriber"}, |
| 19 | + {mfa, {?MODULE, register, []}}, |
| 20 | + {cleanup, {?MODULE, unregister, []}}, |
| 21 | + {requires, rabbit_event}, |
| 22 | + {enables, recovery}]}). |
| 23 | + |
| 24 | +register() -> |
| 25 | + gen_event:add_handler(rabbit_alarm, ?MODULE, []), |
| 26 | + gen_event:add_handler(rabbit_event, ?MODULE, []). |
| 27 | + |
| 28 | +unregister() -> |
| 29 | + gen_event:delete_handler(rabbit_alarm, ?MODULE, []), |
| 30 | + gen_event:delete_handler(rabbit_event, ?MODULE, []). |
| 31 | + |
| 32 | +init([]) -> |
| 33 | + {ok, []}. |
| 34 | + |
| 35 | +handle_call( _, State) -> |
| 36 | + {ok, ok, State}. |
| 37 | + |
| 38 | +handle_event({node_up, Node}, State) -> |
| 39 | + rabbit_quorum_queue_periodic_membership_reconciliation:on_node_up(Node), |
| 40 | + {ok, State}; |
| 41 | +handle_event({node_down, Node}, State) -> |
| 42 | + rabbit_quorum_queue_periodic_membership_reconciliation:on_node_down(Node), |
| 43 | + {ok, State}; |
| 44 | +handle_event(#event{type = policy_set}, State) -> |
| 45 | + rabbit_quorum_queue_periodic_membership_reconciliation:policy_set(), |
| 46 | + {ok, State}; |
| 47 | +handle_event(#event{type = operator_policy_set}, State) -> |
| 48 | + rabbit_quorum_queue_periodic_membership_reconciliation:policy_set(), |
| 49 | + {ok, State}; |
| 50 | +handle_event(_, State) -> |
| 51 | + {ok, State}. |
0 commit comments