1
%% The contents of this file are subject to the Mozilla Public License
2
%% Version 1.1 (the "License"); you may not use this file except in
3
%% compliance with the License. You may obtain a copy of the License
4
%% at http://www.mozilla.org/MPL/
6
%% Software distributed under the License is distributed on an "AS IS"
7
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8
%% the License for the specific language governing rights and
9
%% limitations under the License.
11
%% The Original Code is RabbitMQ Federation.
13
%% The Initial Developer of the Original Code is VMware, Inc.
14
%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved.
17
-module(rabbit_federation_old_db).
19
-include("rabbit_federation_old.hrl").
20
-include_lib("amqp_client/include/amqp_client.hrl").
22
-define(DICT, orddict).
24
-export([get_active_suffix/3, set_active_suffix/3, prune_scratch/2]).
26
%%----------------------------------------------------------------------------
28
get_active_suffix(XName, Upstream, Default) ->
29
case rabbit_exchange:lookup_scratch(XName, federation) of
31
case ?DICT:find(key(Upstream), Dict) of
32
{ok, Suffix} -> Suffix;
39
set_active_suffix(XName, Upstream, Suffix) ->
40
ok = rabbit_exchange:update_scratch(
42
fun(D) -> ?DICT:store(key(Upstream), Suffix, D) end).
44
prune_scratch(XName, Upstreams) ->
45
ok = rabbit_exchange:update_scratch(
47
fun(undefined) -> ?DICT:new();
48
(D) -> Keys = [key(U) || U <- Upstreams],
50
fun(K, _V) -> lists:member(K, Keys) end, D)
53
key(#upstream{connection_name = ConnName, exchange = XName}) ->