~ubuntu-branches/ubuntu/saucy/rabbitmq-server/saucy

« back to all changes in this revision

Viewing changes to src/rabbit_exchange_decorator.erl

  • Committer: Package Import Robot
  • Author(s): Emile Joubert
  • Date: 2013-05-02 11:19:31 UTC
  • mfrom: (0.5.2) (0.1.37 sid)
  • Revision ID: package-import@ubuntu.com-20130502111931-xnoj0sejto2tewcj
Tags: 3.1.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
-module(rabbit_exchange_decorator).
18
18
 
 
19
-include("rabbit.hrl").
 
20
 
 
21
-export([select/2, set/1]).
 
22
 
19
23
%% This is like an exchange type except that:
20
24
%%
21
25
%% 1) It applies to all exchanges as soon as it is installed, therefore
22
26
%% 2) It is not allowed to affect validation, so no validate/1 or
23
27
%%    assert_args_equivalence/2
24
 
%% 3) It also can't affect routing
25
28
%%
26
 
%% It's possible in the future we might relax 3), or even make these
 
29
%% It's possible in the future we might make decorators
27
30
%% able to manipulate messages as they are published.
28
31
 
29
32
-ifdef(use_specs).
46
49
-callback delete(tx(), rabbit_types:exchange(), [rabbit_types:binding()]) ->
47
50
    'ok'.
48
51
 
 
52
%% called when the policy attached to this exchange changes.
 
53
-callback policy_changed(rabbit_types:exchange(), rabbit_types:exchange()) ->
 
54
    'ok'.
 
55
 
49
56
%% called after a binding has been added or recovered
50
57
-callback add_binding(serial(), rabbit_types:exchange(),
51
58
                      rabbit_types:binding()) -> 'ok'.
54
61
-callback remove_bindings(serial(), rabbit_types:exchange(),
55
62
                          [rabbit_types:binding()]) -> 'ok'.
56
63
 
57
 
%% called when the policy attached to this exchange changes.
58
 
-callback policy_changed (
59
 
            serial(), rabbit_types:exchange(), rabbit_types:exchange()) -> 'ok'.
 
64
%% Allows additional destinations to be added to the routing decision.
 
65
-callback route(rabbit_types:exchange(), rabbit_types:delivery()) ->
 
66
    [rabbit_amqqueue:name() | rabbit_exchange:name()].
 
67
 
 
68
%% Whether the decorator wishes to receive callbacks for the exchange
 
69
%% none:no callbacks, noroute:all callbacks except route, all:all callbacks
 
70
-callback active_for(rabbit_types:exchange()) -> 'none' | 'noroute' | 'all'.
60
71
 
61
72
-else.
62
73
 
64
75
 
65
76
behaviour_info(callbacks) ->
66
77
    [{description, 0}, {serialise_events, 1}, {create, 2}, {delete, 3},
67
 
     {add_binding, 3}, {remove_bindings, 3}, {policy_changed, 3}];
 
78
     {policy_changed, 2}, {add_binding, 3}, {remove_bindings, 3},
 
79
     {route, 2}, {active_for, 1}];
68
80
behaviour_info(_Other) ->
69
81
    undefined.
70
82
 
71
83
-endif.
 
84
 
 
85
%%----------------------------------------------------------------------------
 
86
 
 
87
%% select a subset of active decorators
 
88
select(all,   {Route, NoRoute})  -> filter(Route ++ NoRoute);
 
89
select(route, {Route, _NoRoute}) -> filter(Route);
 
90
select(raw,   {Route, NoRoute})  -> Route ++ NoRoute.
 
91
 
 
92
filter(Modules) ->
 
93
    [M || M <- Modules, code:which(M) =/= non_existing].
 
94
 
 
95
set(X) ->
 
96
    Decs = lists:foldl(fun (D, {Route, NoRoute}) ->
 
97
                               ActiveFor = D:active_for(X),
 
98
                               {cons_if_eq(all,     ActiveFor, D, Route),
 
99
                                cons_if_eq(noroute, ActiveFor, D, NoRoute)}
 
100
                       end, {[], []}, list()),
 
101
    X#exchange{decorators = Decs}.
 
102
 
 
103
list() -> [M || {_, M} <- rabbit_registry:lookup_all(exchange_decorator)].
 
104
 
 
105
cons_if_eq(Select,  Select, Item,  List) -> [Item | List];
 
106
cons_if_eq(_Select, _Other, _Item, List) -> List.