summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Joubert <emile@rabbitmq.com>2013-04-11 17:53:15 +0100
committerEmile Joubert <emile@rabbitmq.com>2013-04-11 17:53:15 +0100
commit4b394cc6eb5d4cb8660c574505d4dfe313e61520 (patch)
treed518c3bc40ad446349e1cfdba54d23cf155203fc
parente5c580885cf8cf6e20b0992c3e4c7306504aa1c7 (diff)
downloadrabbitmq-server-git-4b394cc6eb5d4cb8660c574505d4dfe313e61520.tar.gz
Changes
-rw-r--r--src/rabbit_exchange.erl10
-rw-r--r--src/rabbit_exchange_decorator.erl17
2 files changed, 17 insertions, 10 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl
index f5fd9a65a4..c924f53ad2 100644
--- a/src/rabbit_exchange.erl
+++ b/src/rabbit_exchange.erl
@@ -125,8 +125,12 @@ callback(X = #exchange{type = XType,
Module = type_to_module(XType),
apply(Module, Fun, [Serial(Module:serialise_events()) | Args]).
-policy_changed(X = #exchange{type = XType}, X1) ->
- ok = (type_to_module(XType)):policy_changed(X, X1).
+policy_changed(X = #exchange{type = XType,
+ decorators = Decorators}, X1) ->
+ [ok = M:policy_changed(X, X1) ||
+ M <- [type_to_module(XType) |
+ rabbit_exchange_decorator:select(all, Decorators)]],
+ ok.
serialise_events(X = #exchange{type = Type, decorators = Decorators}) ->
lists:any(fun (M) ->
@@ -324,7 +328,7 @@ route1(_, _, {[], _, QNames}) ->
route1(Delivery, Decorators,
{[X = #exchange{type = Type} | WorkList], SeenXs, QNames}) ->
ExchangeDests = (type_to_module(Type)):route(X, Delivery),
- DecorateDests = process_decorators(X, Decorators, Delivery),
+ DecorateDests = process_decorators(X, Decorators, Delivery),
AlternateDests = process_alternate(X, ExchangeDests),
route1(Delivery, Decorators,
lists:foldl(fun process_route/2, {WorkList, SeenXs, QNames},
diff --git a/src/rabbit_exchange_decorator.erl b/src/rabbit_exchange_decorator.erl
index 3748a844a3..3bc9de1ead 100644
--- a/src/rabbit_exchange_decorator.erl
+++ b/src/rabbit_exchange_decorator.erl
@@ -18,7 +18,7 @@
-include("rabbit.hrl").
--export([list/0, select/2, set/1]).
+-export([select/2, set/1]).
%% This is like an exchange type except that:
%%
@@ -49,6 +49,10 @@
-callback delete(tx(), rabbit_types:exchange(), [rabbit_types:binding()]) ->
'ok'.
+%% called when the policy attached to this exchange changes.
+-callback policy_changed(rabbit_types:exchange(), rabbit_types:exchange()) ->
+ 'ok'.
+
%% called after a binding has been added or recovered
-callback add_binding(serial(), rabbit_types:exchange(),
rabbit_types:binding()) -> 'ok'.
@@ -57,10 +61,9 @@
-callback remove_bindings(serial(), rabbit_types:exchange(),
[rabbit_types:binding()]) -> 'ok'.
-%% Decorators can optionally implement route/2 which allows additional
-%% destinations to be added to the routing decision.
-%% -callback route(rabbit_types:exchange(), rabbit_types:delivery()) ->
-%% [rabbit_amqqueue:name() | rabbit_exchange:name()] | ok.
+%% Allows additional destinations to be added to the routing decision.
+-callback route(rabbit_types:exchange(), rabbit_types:delivery()) ->
+ [rabbit_amqqueue:name() | rabbit_exchange:name()] | ok.
%% Whether the decorator wishes to receive callbacks for the exchange
%% none:no callbacks, noroute:all callbacks except route, all:all callbacks
@@ -73,7 +76,7 @@
behaviour_info(callbacks) ->
[{description, 0}, {serialise_events, 1}, {create, 2}, {delete, 3},
{policy_changed, 2}, {add_binding, 3}, {remove_bindings, 3},
- {active_for, 1}];
+ {route, 2}, {active_for, 1}];
behaviour_info(_Other) ->
undefined.
@@ -94,7 +97,7 @@ set(X) ->
Callbacks = D:active_for(X),
{cons_if_eq(all, Callbacks, D, Route),
cons_if_eq(noroute, Callbacks, D, NoRoute)}
- end, {[], []}, rabbit_exchange_decorator:list())}.
+ end, {[], []}, list())}.
cons_if_eq(Select, Select, Item, List) -> [Item | List];
cons_if_eq(_Select, _Other, _Item, List) -> List.