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

« back to all changes in this revision

Viewing changes to plugins-src/rabbitmq-old-federation/src/rabbit_federation_old_db.erl

  • Committer: Package Import Robot
  • Author(s): Emile Joubert
  • Date: 2012-11-19 11:42:31 UTC
  • mfrom: (0.2.18) (0.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20121119114231-hvapkn4akng09etr
Tags: 3.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/
 
5
%%
 
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.
 
10
%%
 
11
%% The Original Code is RabbitMQ Federation.
 
12
%%
 
13
%% The Initial Developer of the Original Code is VMware, Inc.
 
14
%% Copyright (c) 2007-2012 VMware, Inc.  All rights reserved.
 
15
%%
 
16
 
 
17
-module(rabbit_federation_old_db).
 
18
 
 
19
-include("rabbit_federation_old.hrl").
 
20
-include_lib("amqp_client/include/amqp_client.hrl").
 
21
 
 
22
-define(DICT, orddict).
 
23
 
 
24
-export([get_active_suffix/3, set_active_suffix/3, prune_scratch/2]).
 
25
 
 
26
%%----------------------------------------------------------------------------
 
27
 
 
28
get_active_suffix(XName, Upstream, Default) ->
 
29
    case rabbit_exchange:lookup_scratch(XName, federation) of
 
30
        {ok, Dict} ->
 
31
            case ?DICT:find(key(Upstream), Dict) of
 
32
                {ok, Suffix} -> Suffix;
 
33
                error        -> Default
 
34
            end;
 
35
        {error, not_found} ->
 
36
            Default
 
37
    end.
 
38
 
 
39
set_active_suffix(XName, Upstream, Suffix) ->
 
40
    ok = rabbit_exchange:update_scratch(
 
41
           XName, federation,
 
42
           fun(D) -> ?DICT:store(key(Upstream), Suffix, D) end).
 
43
 
 
44
prune_scratch(XName, Upstreams) ->
 
45
    ok = rabbit_exchange:update_scratch(
 
46
           XName, federation,
 
47
           fun(undefined) -> ?DICT:new();
 
48
              (D)         -> Keys = [key(U) || U <- Upstreams],
 
49
                             ?DICT:filter(
 
50
                                fun(K, _V) -> lists:member(K, Keys) end, D)
 
51
           end).
 
52
 
 
53
key(#upstream{connection_name = ConnName, exchange = XName}) ->
 
54
    {ConnName, XName}.