summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2010-07-02 13:08:02 +0100
committerSimon MacMullen <simon@rabbitmq.com>2010-07-02 13:08:02 +0100
commita9011fca063dc68662c4984cbc4407f8a98c72bd (patch)
tree3196c28f0313763e437ea38e595f4968d0638109 /src
parentbc482e7ffcc2cea901419f738ac7cb9db4aa6182 (diff)
downloadrabbitmq-server-git-a9011fca063dc68662c4984cbc4407f8a98c72bd.tar.gz
Remove the rabbit_framing shim, pass around a module name and use that.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_basic.erl4
-rw-r--r--src/rabbit_binary_generator.erl9
-rw-r--r--src/rabbit_binary_parser.erl2
-rw-r--r--src/rabbit_channel.erl2
-rw-r--r--src/rabbit_framing.erl102
-rw-r--r--src/rabbit_framing_channel.erl7
-rw-r--r--src/rabbit_reader.erl29
-rw-r--r--src/rabbit_tests.erl5
-rw-r--r--src/rabbit_writer.erl2
9 files changed, 33 insertions, 129 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl
index e277d5b77a..7b581b8d07 100644
--- a/src/rabbit_basic.erl
+++ b/src/rabbit_basic.erl
@@ -82,7 +82,7 @@ delivery(Mandatory, Immediate, Txn, Message) ->
build_content(Properties, BodyBin) ->
%% basic.publish hasn't changed so we can just hard-code amqp_0_9_1
{ClassId, _MethodId} =
- rabbit_framing:method_id('basic.publish', amqp_0_9_1),
+ rabbit_framing_amqp_0_9_1:method_id('basic.publish'),
#content{class_id = ClassId,
properties = Properties,
properties_bin = none,
@@ -95,7 +95,7 @@ from_content(Content) ->
rabbit_binary_parser:ensure_content_decoded(Content),
%% basic.publish hasn't changed so we can just hard-code amqp_0_9_1
{ClassId, _MethodId} =
- rabbit_framing:method_id('basic.publish', amqp_0_9_1),
+ rabbit_framing_amqp_0_9_1:method_id('basic.publish'),
{Props, list_to_binary(lists:reverse(FragmentsRev))}.
message(ExchangeName, RoutingKeyBin, RawProperties, BodyBin) ->
diff --git a/src/rabbit_binary_generator.erl b/src/rabbit_binary_generator.erl
index 04251d11fc..d159f30928 100644
--- a/src/rabbit_binary_generator.erl
+++ b/src/rabbit_binary_generator.erl
@@ -72,9 +72,9 @@
%%----------------------------------------------------------------------------
build_simple_method_frame(ChannelInt, MethodRecord, Protocol) ->
- MethodFields = rabbit_framing:encode_method_fields(MethodRecord, Protocol),
+ MethodFields = Protocol:encode_method_fields(MethodRecord),
MethodName = rabbit_misc:method_record_type(MethodRecord),
- {ClassId, MethodId} = rabbit_framing:method_id(MethodName, Protocol),
+ {ClassId, MethodId} = Protocol:method_id(MethodName),
create_frame(1, ChannelInt, [<<ClassId:16, MethodId:16>>, MethodFields]).
build_simple_content_frames(ChannelInt,
@@ -93,7 +93,7 @@ maybe_encode_properties(_ContentProperties, ContentPropertiesBin)
when is_binary(ContentPropertiesBin) ->
ContentPropertiesBin;
maybe_encode_properties(ContentProperties, none) ->
- rabbit_framing:encode_properties(ContentProperties).
+ rabbit_framing_amqp_0_9_1:encode_properties(ContentProperties).
build_content_frames(FragsRev, FrameMax, ChannelInt) ->
BodyPayloadMax = if FrameMax == 0 ->
@@ -281,7 +281,8 @@ ensure_content_encoded(Content = #content{properties_bin = PropsBin})
when PropsBin =/= 'none' ->
Content;
ensure_content_encoded(Content = #content{properties = Props}) ->
- Content #content{properties_bin = rabbit_framing:encode_properties(Props)}.
+ Content #content{properties_bin =
+ rabbit_framing_amqp_0_9_1:encode_properties(Props)}.
clear_encoded_content(Content = #content{properties_bin = none}) ->
Content;
diff --git a/src/rabbit_binary_parser.erl b/src/rabbit_binary_parser.erl
index e022a1fafe..7a32acaef5 100644
--- a/src/rabbit_binary_parser.erl
+++ b/src/rabbit_binary_parser.erl
@@ -164,7 +164,7 @@ ensure_content_decoded(Content = #content{properties = Props})
Content;
ensure_content_decoded(Content = #content{properties_bin = PropBin})
when is_binary(PropBin) ->
- Content#content{properties = rabbit_framing:decode_properties(
+ Content#content{properties = rabbit_framing_amqp_0_9_1:decode_properties(
Content#content.class_id, PropBin)}.
clear_decoded_content(Content = #content{properties = none}) ->
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl
index 1a965f7984..f2a3e07121 100644
--- a/src/rabbit_channel.erl
+++ b/src/rabbit_channel.erl
@@ -930,7 +930,7 @@ basic_return(#basic_message{exchange_name = ExchangeName,
content = Content},
WriterPid, Reason) ->
{_Close, ReplyCode, ReplyText} =
- rabbit_framing:lookup_amqp_exception(Reason),
+ rabbit_framing_amqp_0_9_1:lookup_amqp_exception(Reason),
ok = rabbit_writer:send_command(
WriterPid,
#'basic.return'{reply_code = ReplyCode,
diff --git a/src/rabbit_framing.erl b/src/rabbit_framing.erl
deleted file mode 100644
index 2d4d1ce411..0000000000
--- a/src/rabbit_framing.erl
+++ /dev/null
@@ -1,102 +0,0 @@
-%% 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 Developers of the Original Code are LShift Ltd,
-%% Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
-%%
-%% Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
-%% Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
-%% are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
-%% Technologies LLC, and Rabbit Technologies Ltd.
-%%
-%% Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift
-%% Ltd. Portions created by Cohesive Financial Technologies LLC are
-%% Copyright (C) 2007-2010 Cohesive Financial Technologies
-%% LLC. Portions created by Rabbit Technologies Ltd are Copyright
-%% (C) 2007-2010 Rabbit Technologies Ltd.
-%%
-%% All Rights Reserved.
-%%
-%% Contributor(s): ______________________________________.
-%%
--module(rabbit_framing).
--include("rabbit.hrl").
--include("rabbit_framing.hrl").
-
-
--export([encode_method_fields/2]).
--export([decode_method_fields/3]).
--export([lookup_method_name/2]).
--export([method_id/2]).
-
--export([method_has_content/1]).
--export([is_method_synchronous/1]).
--export([method_record/1]).
--export([method_fieldnames/1]).
--export([decode_properties/2]).
--export([encode_properties/1]).
--export([lookup_amqp_exception/1]).
--export([amqp_exception/1]).
-
-%% Method signatures
--ifdef(use_specs).
--spec(encode_method_fields/2 :: (amqp_method_record(), protocol()) -> binary()).
--spec(decode_method_fields/3 :: (amqp_method_name(), binary(), protocol()) ->
- amqp_method_record()).
--spec(lookup_method_name/2 :: (amqp_method(), protocol()) ->
- amqp_method_name()).
--spec(method_id/2 :: (amqp_method_name(), protocol()) -> amqp_method()).
-
--spec(method_has_content/1 :: (amqp_method_name()) -> boolean()).
--spec(is_method_synchronous/1 :: (amqp_method_record()) -> boolean()).
--spec(method_record/1 :: (amqp_method_name()) -> amqp_method_record()).
--spec(method_fieldnames/1 :: (amqp_method_name()) ->
- [amqp_method_field_name()]).
--spec(decode_properties/2 :: (non_neg_integer(), binary()) ->
- amqp_property_record()).
--spec(encode_properties/1 :: (amqp_method_record()) -> binary()).
--spec(lookup_amqp_exception/1 ::
- (amqp_exception()) -> {boolean(), amqp_exception_code(), binary()}).
--spec(amqp_exception/1 :: (amqp_exception_code()) -> amqp_exception()).
--endif. % use_specs
-
-encode_method_fields(MethodRecord, amqp_0_9_1) ->
- rabbit_framing_amqp_0_9_1:encode_method_fields(MethodRecord);
-encode_method_fields(MethodRecord, amqp_0_8) ->
- rabbit_framing_amqp_0_8:encode_method_fields(MethodRecord).
-
-decode_method_fields(MethodName, FieldsBin, amqp_0_9_1) ->
- rabbit_framing_amqp_0_9_1:decode_method_fields(MethodName, FieldsBin);
-decode_method_fields(MethodName, FieldsBin, amqp_0_8) ->
- rabbit_framing_amqp_0_8:decode_method_fields(MethodName, FieldsBin).
-
-lookup_method_name(ClassMethod, amqp_0_9_1) ->
- rabbit_framing_amqp_0_9_1:lookup_method_name(ClassMethod);
-lookup_method_name(ClassMethod, amqp_0_8) ->
- rabbit_framing_amqp_0_8:lookup_method_name(ClassMethod).
-
-method_id(MethodName, amqp_0_9_1) ->
- rabbit_framing_amqp_0_9_1:method_id(MethodName);
-method_id(MethodName, amqp_0_8) ->
- rabbit_framing_amqp_0_8:method_id(MethodName).
-
-
-
-%% These ones don't make any difference, let's just use 0-9-1.
-method_has_content(X) -> rabbit_framing_amqp_0_9_1:method_has_content(X).
-method_record(X) -> rabbit_framing_amqp_0_9_1:method_record(X).
-method_fieldnames(X) -> rabbit_framing_amqp_0_9_1:method_fieldnames(X).
-encode_properties(X) -> rabbit_framing_amqp_0_9_1:encode_properties(X).
-amqp_exception(X) -> rabbit_framing_amqp_0_9_1:amqp_exception(X).
-lookup_amqp_exception(X) -> rabbit_framing_amqp_0_9_1:lookup_amqp_exception(X).
-is_method_synchronous(X) -> rabbit_framing_amqp_0_9_1:is_method_synchronous(X).
-decode_properties(X, Y) -> rabbit_framing_amqp_0_9_1:decode_properties(X, Y).
diff --git a/src/rabbit_framing_channel.erl b/src/rabbit_framing_channel.erl
index c30cf45143..7b9607cb0e 100644
--- a/src/rabbit_framing_channel.erl
+++ b/src/rabbit_framing_channel.erl
@@ -74,9 +74,8 @@ read_frame(ChannelPid) ->
mainloop(ChannelPid, Protocol) ->
{method, MethodName, FieldsBin} = read_frame(ChannelPid),
- Method = rabbit_framing:decode_method_fields(MethodName, FieldsBin,
- Protocol),
- case rabbit_framing:method_has_content(MethodName) of
+ Method = Protocol:decode_method_fields(MethodName, FieldsBin),
+ case Protocol:method_has_content(MethodName) of
true -> rabbit_channel:do(ChannelPid, Method,
collect_content(ChannelPid, MethodName));
false -> rabbit_channel:do(ChannelPid, Method)
@@ -85,7 +84,7 @@ mainloop(ChannelPid, Protocol) ->
collect_content(ChannelPid, MethodName) ->
%% Protocol does not matter as we only want the class ID to match
- {ClassId, _MethodId} = rabbit_framing:method_id(MethodName, amqp_0_9_1),
+ {ClassId, _MethodId} = rabbit_framing_amqp_0_9_1:method_id(MethodName),
case read_frame(ChannelPid) of
{content_header, HeaderClassId, 0, BodySize, PropertiesBin} ->
if HeaderClassId == ClassId ->
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index a9862367d4..4a8b0f3c7a 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -523,7 +523,7 @@ handle_frame(Type, Channel, Payload,
analyze_frame(?FRAME_METHOD, <<ClassId:16, MethodId:16, MethodFields/binary>>,
Protocol) ->
- {method, rabbit_framing:lookup_method_name({ClassId, MethodId}, Protocol),
+ {method, Protocol:lookup_method_name({ClassId, MethodId}),
MethodFields};
analyze_frame(?FRAME_HEADER,
<<ClassId:16, Weight:16, BodySize:64, Properties/binary>>,
@@ -580,8 +580,13 @@ handle_input(Callback, Data, _State) ->
%% Offer a protocol version to the client. Connection.start only
%% includes a major and minor version number, Luckily 0-9 and 0-9-1
%% are similar enough that clients will be happy with either.
-start_connection({ProtocolMajor, ProtocolMinor, _ProtocolRevision}, Protocol,
- State = #v1{sock = Sock, connection = Connection}) ->
+start_connection({ProtocolMajor, ProtocolMinor, _ProtocolRevision},
+ ProtocolName,
+ State = #v1{sock = Sock, connection = Connection}) ->
+ Protocol = case ProtocolName of
+ amqp_0_9_1 -> rabbit_framing_amqp_0_9_1;
+ amqp_0_8 -> rabbit_framing_amqp_0_8
+ end,
ok = send_on_channel0(
Sock,
#'connection.start'{
@@ -593,7 +598,8 @@ start_connection({ProtocolMajor, ProtocolMinor, _ProtocolRevision}, Protocol,
Protocol),
{State#v1{connection = Connection#connection{
timeout_sec = ?NORMAL_TIMEOUT,
- protocol = Protocol},
+ protocol = Protocol,
+ protocol_name = ProtocolName},
connection_state = starting},
frame_header, 7}.
@@ -606,8 +612,7 @@ refuse_connection(Sock, Exception) ->
handle_method0(MethodName, FieldsBin,
State = #v1{connection = #connection{protocol = Protocol}}) ->
try
- handle_method0(rabbit_framing:decode_method_fields(
- MethodName, FieldsBin, Protocol),
+ handle_method0(Protocol:decode_method_fields(MethodName, FieldsBin),
State)
catch exit:Reason ->
CompleteReason = case Reason of
@@ -723,8 +728,8 @@ i(peer_address, #v1{sock = Sock}) ->
i(peer_port, #v1{sock = Sock}) ->
{ok, {_, P}} = rabbit_net:peername(Sock),
P;
-i(protocol, #v1{connection = #connection{protocol = Protocol}}) ->
- Protocol;
+i(protocol, #v1{connection = #connection{protocol_name = ProtocolName}}) ->
+ ProtocolName;
i(SockStat, #v1{sock = Sock}) when SockStat =:= recv_oct;
SockStat =:= recv_cnt;
SockStat =:= send_oct;
@@ -805,8 +810,7 @@ map_exception(Channel, Reason, Protocol) ->
{ClassId, MethodId} = case FailedMethod of
{_, _} -> FailedMethod;
none -> {0, 0};
- _ -> rabbit_framing:method_id(FailedMethod,
- Protocol)
+ _ -> Protocol:method_id(FailedMethod)
end,
{CloseChannel, CloseMethod} =
case ShouldClose of
@@ -830,13 +834,14 @@ lookup_amqp_exception(#amqp_error{name = precondition_failed,
lookup_amqp_exception(#amqp_error{name = Name,
explanation = Expl,
method = Method}) ->
- {ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(Name),
+ {ShouldClose, Code, Text} =
+ rabbit_framing_amqp_0_9_1:lookup_amqp_exception(Name),
ExplBin = amqp_exception_explanation(Text, Expl),
{ShouldClose, Code, ExplBin, Method};
lookup_amqp_exception(Other) ->
rabbit_log:warning("Non-AMQP exit reason '~p'~n", [Other]),
{ShouldClose, Code, Text} =
- rabbit_framing:lookup_amqp_exception(internal_error),
+ rabbit_framing_0_9_1:lookup_amqp_exception(internal_error),
{ShouldClose, Code, Text, none}.
amqp_exception_explanation(Text, Expl) ->
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 87eaae9e24..6d9d2d389c 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -953,8 +953,9 @@ test_memory_pressure() ->
ok = test_memory_pressure_receive_flow(true),
%% if we publish at this point, the channel should die
- Content = #content{class_id = element(1, rabbit_framing:method_id(
- 'basic.publish', amqp_0_9_1)),
+ Content =
+ #content{class_id = element(1, rabbit_framing_amqp_0_9_1:method_id(
+ 'basic.publish')),
properties = none,
properties_bin = <<>>,
payload_fragments_rev = []},
diff --git a/src/rabbit_writer.erl b/src/rabbit_writer.erl
index 403120f150..17b8f53ef8 100644
--- a/src/rabbit_writer.erl
+++ b/src/rabbit_writer.erl
@@ -170,7 +170,7 @@ assemble_frames(Channel, MethodRecord, Protocol) ->
assemble_frames(Channel, MethodRecord, Content, FrameMax, Protocol) ->
?LOGMESSAGE(out, Channel, MethodRecord, Content),
MethodName = rabbit_misc:method_record_type(MethodRecord),
- true = rabbit_framing:method_has_content(MethodName), % assertion
+ true = Protocol:method_has_content(MethodName), % assertion
MethodFrame = rabbit_binary_generator:build_simple_method_frame(
Channel, MethodRecord, Protocol),
ContentFrames = rabbit_binary_generator:build_simple_content_frames(