diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2012-04-24 14:32:57 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2012-04-24 14:32:57 +0100 |
| commit | 42c84b030194497f12cceb805ed1cb127375f041 (patch) | |
| tree | c3ce1bcec09833a4798d6e242675a97a422e93ef | |
| parent | 7e2a6d9569742393e3f63a93fdc4c60dcbf18de0 (diff) | |
| parent | 735b9004facf1963c468685bef3648acdb3bbdb2 (diff) | |
| download | rabbitmq-server-git-42c84b030194497f12cceb805ed1cb127375f041.tar.gz | |
Merge bug24196
| -rw-r--r-- | src/rabbit_exchange.erl | 12 | ||||
| -rw-r--r-- | src/rabbit_exchange_decorator.erl | 46 | ||||
| -rw-r--r-- | src/rabbit_registry.erl | 7 |
3 files changed, 60 insertions, 5 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 910a89b42c..6c82bc7b89 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -101,7 +101,15 @@ recover() -> [XName || #exchange{name = XName} <- Xs]. callback(#exchange{type = XType}, Fun, Args) -> - apply(type_to_module(XType), Fun, Args). + callback(type_to_module(XType), Fun, Args); + +callback(Module, Fun, Args) -> + %% TODO cache this? + %% TODO what about serialising events? + %% TODO what about sharing the scratch space? + Decorators = rabbit_registry:lookup_all(exchange_decorator), + [ok = apply(M, Fun, Args) || {_, M} <- Decorators], + apply(Module, Fun, Args). declare(XName, Type, Durable, AutoDelete, Internal, Args) -> X = #exchange{name = XName, @@ -129,7 +137,7 @@ declare(XName, Type, Durable, AutoDelete, Internal, Args) -> end end, fun ({new, Exchange}, Tx) -> - ok = XT:create(map_create_tx(Tx), Exchange), + ok = callback(XT, create, [map_create_tx(Tx), Exchange]), rabbit_event:notify_if(not Tx, exchange_created, info(Exchange)), Exchange; ({existing, Exchange}, _Tx) -> diff --git a/src/rabbit_exchange_decorator.erl b/src/rabbit_exchange_decorator.erl new file mode 100644 index 0000000000..362ec30964 --- /dev/null +++ b/src/rabbit_exchange_decorator.erl @@ -0,0 +1,46 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is VMware, Inc. +%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved. +%% + +-module(rabbit_exchange_decorator). + +-export([behaviour_info/1]). + +behaviour_info(callbacks) -> + [ + {description, 0}, + + %% Should Rabbit ensure that all binding events that are + %% delivered to an individual exchange can be serialised? (they + %% might still be delivered out of order, but there'll be a + %% serial number). + {serialise_events, 0}, + + {route, 2}, + + %% called after declaration and recovery + {create, 2}, + + %% called after exchange (auto)deletion. + {delete, 3}, + + %% called after a binding has been added or recovered + {add_binding, 3}, + + %% called after bindings have been deleted. + {remove_bindings, 3} + ]; +behaviour_info(_Other) -> + undefined. diff --git a/src/rabbit_registry.erl b/src/rabbit_registry.erl index 637835c327..e14bbba018 100644 --- a/src/rabbit_registry.erl +++ b/src/rabbit_registry.erl @@ -104,9 +104,10 @@ sanity_check_module(ClassModule, Module) -> true -> ok end. -class_module(exchange) -> rabbit_exchange_type; -class_module(auth_mechanism) -> rabbit_auth_mechanism; -class_module(runtime_parameter) -> rabbit_runtime_parameter. +class_module(exchange) -> rabbit_exchange_type; +class_module(auth_mechanism) -> rabbit_auth_mechanism; +class_module(runtime_parameter) -> rabbit_runtime_parameter; +class_module(exchange_decorator) -> rabbit_exchange_decorator. %%--------------------------------------------------------------------------- |
