summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rabbit_policies.erl15
-rw-r--r--src/rabbit_policy.erl17
-rw-r--r--src/rabbit_policy_merge_strategy.erl28
3 files changed, 50 insertions, 10 deletions
diff --git a/src/rabbit_policies.erl b/src/rabbit_policies.erl
index c30b4ca148..22eb3fde18 100644
--- a/src/rabbit_policies.erl
+++ b/src/rabbit_policies.erl
@@ -20,10 +20,11 @@
%% validation functions.
-behaviour(rabbit_policy_validator).
+-behaviour(rabbit_policy_merge_strategy).
-include("rabbit.hrl").
--export([register/0, validate_policy/1]).
+-export([register/0, validate_policy/1, merge_policy_value/3]).
-rabbit_boot_step({?MODULE,
[{description, "internal policies"},
@@ -44,7 +45,11 @@ register() ->
{operator_policy_validator, <<"expires">>},
{operator_policy_validator, <<"message-ttl">>},
{operator_policy_validator, <<"max-length">>},
- {operator_policy_validator, <<"max-length-bytes">>}]],
+ {operator_policy_validator, <<"max-length-bytes">>},
+ {policy_merge_strategy, <<"expires">>},
+ {policy_merge_strategy, <<"message-ttl">>},
+ {policy_merge_strategy, <<"max-length">>},
+ {policy_merge_strategy, <<"max-length-bytes">>}]],
ok.
validate_policy(Terms) ->
@@ -100,3 +105,9 @@ validate_policy0(<<"queue-mode">>, <<"lazy">>) ->
ok;
validate_policy0(<<"queue-mode">>, Value) ->
{error, "~p is not a valid queue-mode value", [Value]}.
+
+merge_policy_value(<<"message-ttl">>, Val, OpVal) -> min(Val, OpVal);
+merge_policy_value(<<"max-length">>, Val, OpVal) -> min(Val, OpVal);
+merge_policy_value(<<"max-length-bytes">>, Val, OpVal) -> min(Val, OpVal);
+merge_policy_value(<<"expires">>, Val, OpVal) -> min(Val, OpVal).
+
diff --git a/src/rabbit_policy.erl b/src/rabbit_policy.erl
index 7cb1231e4d..f5b6c8d535 100644
--- a/src/rabbit_policy.erl
+++ b/src/rabbit_policy.erl
@@ -127,16 +127,17 @@ get0(Name, Policy, OpPolicy) ->
merge_policy_value(Name, PolicyVal, OpVal) ->
case policy_merge_strategy(Name) of
- undefined -> PolicyVal;
- Strategy -> Strategy(PolicyVal, OpVal)
+ {ok, Module} -> Module:merge_policy_value(Name, PolicyVal, OpVal);
+ {error, not_found} -> PolicyVal
end.
-policy_merge_strategy(<<"message-ttl">>) -> fun erlang:min/2;
-policy_merge_strategy(<<"max-length">>) -> fun erlang:min/2;
-policy_merge_strategy(<<"max-length-bytes">>) -> fun erlang:min/2;
-policy_merge_strategy(<<"expires">>) -> fun erlang:min/2;
-policy_merge_strategy(_) -> undefined.
-
+policy_merge_strategy(Name) ->
+ case rabbit_registry:binary_to_type(Name) of
+ {error, not_found} ->
+ {error, not_found};
+ T ->
+ rabbit_registry:lookup_module(policy_merge_strategy, T)
+ end.
%% Many heads for optimisation
get_arg(_AName, _PName, #exchange{arguments = [], policy = undefined}) ->
diff --git a/src/rabbit_policy_merge_strategy.erl b/src/rabbit_policy_merge_strategy.erl
new file mode 100644
index 0000000000..55ad87ccac
--- /dev/null
+++ b/src/rabbit_policy_merge_strategy.erl
@@ -0,0 +1,28 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
+%%
+
+-module(rabbit_policy_merge_strategy).
+
+-behaviour(rabbit_registry_class).
+
+-export([added_to_rabbit_registry/2, removed_from_rabbit_registry/1]).
+
+-callback merge_policy_value(binary(), Value, Value) ->
+ Value
+ when Value :: term().
+
+added_to_rabbit_registry(_Type, _ModuleName) -> ok.
+removed_from_rabbit_registry(_Type) -> ok.