diff options
| author | Matthias Radestock <matthias@rabbitmq.com> | 2010-09-27 23:20:47 +0100 |
|---|---|---|
| committer | Matthias Radestock <matthias@rabbitmq.com> | 2010-09-27 23:20:47 +0100 |
| commit | 5977cb8cc07184c1a0582b140d718231d596ee3c (patch) | |
| tree | dd5ebfd1d96a56276e237e676cd1272ce2bf0e3e /src | |
| parent | f4f7ac076d51ef9b2fd2e8cac7097d2f161706bc (diff) | |
| download | rabbitmq-server-git-5977cb8cc07184c1a0582b140d718231d596ee3c.tar.gz | |
generalise binding code somewhat to mostly abstract away the source kind
- not completely, since that would require substantial changes, but
enough to make the code more pleasing to the eye
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_binding.erl | 24 | ||||
| -rw-r--r-- | src/rabbit_router.erl | 8 | ||||
| -rw-r--r-- | src/rabbit_types.erl | 7 |
3 files changed, 21 insertions, 18 deletions
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl index 78403b81a8..0199a35469 100644 --- a/src/rabbit_binding.erl +++ b/src/rabbit_binding.erl @@ -67,11 +67,12 @@ -spec(remove/2 :: (rabbit_types:binding(), inner_fun()) -> bind_res() | rabbit_types:error('binding_not_found')). -spec(list/1 :: (rabbit_types:vhost()) -> bindings()). --spec(list_for_source/1 :: (rabbit_exchange:name()) -> bindings()). --spec(list_for_destination/1 :: (rabbit_types:binding_destination()) -> - bindings()). +-spec(list_for_source/1 :: + (rabbit_types:binding_source()) -> bindings()). +-spec(list_for_destination/1 :: + (rabbit_types:binding_destination()) -> bindings()). -spec(list_for_source_and_destination/2 :: - (rabbit_exchange:name(), rabbit_types:binding_destination()) -> + (rabbit_types:binding_source(), rabbit_types:binding_destination()) -> bindings()). -spec(info_keys/0 :: () -> [rabbit_types:info_key()]). -spec(info/1 :: (rabbit_types:binding()) -> [rabbit_types:info()]). @@ -80,8 +81,8 @@ -spec(info_all/1 :: (rabbit_types:vhost()) -> [[rabbit_types:info()]]). -spec(info_all/2 ::(rabbit_types:vhost(), [rabbit_types:info_key()]) -> [[rabbit_types:info()]]). --spec(has_for_source/1 :: (rabbit_exchange:name()) -> boolean()). --spec(remove_for_source/1 :: (rabbit_exchange:name()) -> bindings()). +-spec(has_for_source/1 :: (rabbit_types:binding_source()) -> boolean()). +-spec(remove_for_source/1 :: (rabbit_types:binding_source()) -> bindings()). -spec(remove_for_destination/1 :: (rabbit_types:binding_destination()) -> fun (() -> any())). -spec(remove_transient_for_destination/1 :: @@ -282,12 +283,10 @@ sync_binding(Binding, Durable, Fun) -> ok. call_with_source_and_destination(SrcName, DstName, Fun) -> - DstTable = case DstName#resource.kind of - queue -> rabbit_queue; - exchange -> rabbit_exchange - end, + SrcTable = table_for_resource(SrcName), + DstTable = table_for_resource(DstName), rabbit_misc:execute_mnesia_transaction( - fun () -> case {mnesia:read({rabbit_exchange, SrcName}), + fun () -> case {mnesia:read({SrcTable, SrcName}), mnesia:read({DstTable, DstName})} of {[Src], [Dst]} -> Fun(Src, Dst); {[], [_] } -> {error, source_not_found}; @@ -296,6 +295,9 @@ call_with_source_and_destination(SrcName, DstName, Fun) -> end end). +table_for_resource(#resource{kind = exchange}) -> rabbit_exchange; +table_for_resource(#resource{kind = queue}) -> rabbit_queue. + %% Used with atoms from records; e.g., the type is expected to exist. type_to_module(T) -> {ok, Module} = rabbit_exchange_type_registry:lookup_module(T), diff --git a/src/rabbit_router.erl b/src/rabbit_router.erl index a2fbd3cab2..6f91633ecb 100644 --- a/src/rabbit_router.erl +++ b/src/rabbit_router.erl @@ -48,11 +48,11 @@ -spec(deliver/2 :: (qpids(), rabbit_types:delivery()) -> {routing_result(), qpids()}). --spec(match_bindings/2 :: (rabbit_exchange:name(), +-spec(match_bindings/2 :: (rabbit_types:binding_source(), fun ((rabbit_types:binding()) -> boolean())) -> match_result()). --spec(match_routing_key/2 :: (rabbit_exchange:name(), routing_key() | '_') -> - match_result()). +-spec(match_routing_key/2 :: (rabbit_types:binding_source(), + routing_key() | '_') -> match_result()). -endif. @@ -83,7 +83,7 @@ deliver(QPids, Delivery) -> {Routed, Handled}). %% TODO: Maybe this should be handled by a cursor instead. -%% TODO: This causes a full scan for each entry with the same exchange +%% TODO: This causes a full scan for each entry with the same source match_bindings(SrcName, Match) -> Query = qlc:q([DestinationName || #route{binding = Binding = #binding{ diff --git a/src/rabbit_types.erl b/src/rabbit_types.erl index 603c45bd1d..b971a63f72 100644 --- a/src/rabbit_types.erl +++ b/src/rabbit_types.erl @@ -39,7 +39,8 @@ delivery/0, content/0, decoded_content/0, undecoded_content/0, unencoded_content/0, encoded_content/0, vhost/0, ctag/0, amqp_error/0, r/1, r2/2, r3/3, listener/0, - binding/0, binding_destination/0, amqqueue/0, exchange/0, + binding/0, binding_source/0, binding_destination/0, + amqqueue/0, exchange/0, connection/0, protocol/0, user/0, ok/1, error/1, ok_or_error/1, ok_or_error2/2, ok_pid_or_error/0, channel_exit/0, connection_exit/0]). @@ -114,8 +115,8 @@ host :: rabbit_networking:hostname(), port :: rabbit_networking:ip_port()}). --type(binding_destination() :: - rabbit_amqqueue:name() | rabbit_exchange:name()). +-type(binding_source() :: rabbit_exchange:name()). +-type(binding_destination() :: rabbit_amqqueue:name() | rabbit_exchange:name()). -type(binding() :: #binding{source :: rabbit_exchange:name(), |
