Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Merging bug 22180 into default
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Sackman committed Oct 12, 2010
2 parents 1867af9 + f617f2c commit 170d151
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 22 deletions.
1 change: 1 addition & 0 deletions ebin/amqp_client.app.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
]},
{registered, []},
{env, []},
{mod, {amqp_client, []}},
{applications, [kernel, stdlib]}]}.
48 changes: 48 additions & 0 deletions src/amqp_client.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
%% 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 the RabbitMQ Erlang Client.
%%
%% The Initial Developers of the Original Code are LShift Ltd.,
%% Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
%%
%% Portions created by LShift Ltd., Cohesive Financial
%% Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
%% 2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
%% Technologies Ltd.;
%%
%% All Rights Reserved.
%%
%% Contributor(s): ____________________.

%% @private
-module(amqp_client).

-behaviour(application).

-export([start/0]).
-export([start/2, stop/1]).

%%---------------------------------------------------------------------------
%% Interface
%%---------------------------------------------------------------------------

start() ->
application:start(amqp_client).

%%---------------------------------------------------------------------------
%% application callbacks
%%---------------------------------------------------------------------------

start(_StartType, _StartArgs) ->
amqp_sup:start_link().

stop(_State) ->
ok.
4 changes: 3 additions & 1 deletion src/amqp_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ start(Type) ->
%% a RabbitMQ server, assuming that the server is running in the same process
%% space.
start(Type, AmqpParams) ->
{ok, _Sup, Connection} = amqp_connection_sup:start_link(Type, AmqpParams),
amqp_client:start(),
{ok, _Sup, Connection} =
amqp_sup:start_connection_sup(Type, AmqpParams),
Module = case Type of direct -> amqp_direct_connection;
network -> amqp_network_connection
end,
Expand Down
1 change: 0 additions & 1 deletion src/amqp_connection_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

start_link(Type, AmqpParams) ->
{ok, Sup} = supervisor2:start_link(?MODULE, []),
unlink(Sup),
{ok, ChSupSup} = supervisor2:start_child(
Sup,
{channel_sup_sup, {amqp_channel_sup_sup, start_link,
Expand Down
11 changes: 2 additions & 9 deletions src/amqp_main_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,8 @@ init([Sock, Connection, ChMgr, Framing0]) ->
{ok, #state{sock = Sock, connection = Connection,
channels_manager = ChMgr, framing0 = Framing0}}.

terminate(Reason, #state{sock = Sock}) ->
Nice = case Reason of normal -> true;
shutdown -> true;
{shutdown, _} -> true;
_ -> false
end,
ok = case Nice of true -> rabbit_net:close(Sock);
false -> ok
end.
terminate(_Reason, _State) ->
ok.

code_change(_OldVsn, State, _Extra) ->
State.
Expand Down
14 changes: 5 additions & 9 deletions src/amqp_network_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ handle_method(#'connection.close'{} = Close, none, State) ->
#closing{reason = server_initiated_close,
close = Close},
State)};
handle_method(#'connection.close_ok'{}, none,
State = #state{closing = Closing}) ->
handle_method(#'connection.close_ok'{}, none, State = #state{closing = Closing,
sock = Sock}) ->
ok = rabbit_net:close(Sock),
#closing{from = From,
close = #'connection.close'{reply_code = ReplyCode}} = Closing,
case From of
none -> ok;
_ -> gen_server:reply(From, ok)
case From of none -> ok;
_ -> gen_server:reply(From, ok)
end,
if ReplyCode =:= 200 -> {stop, normal, State};
true -> {stop, closing_to_reason(Closing), State}
Expand Down Expand Up @@ -397,10 +397,6 @@ start_ok(#state{params = #amqp_params{username = Username,
response = rabbit_binary_generator:generate_table(LoginTable)}.

client_properties(UserProperties) ->
%% TODO This eagerly starts the amqp_client application in order to
%% to get the version from the app descriptor, which may be
%% overkill - maybe there is a more suitable point to boot the app
rabbit_misc:start_applications([amqp_client]),
{ok, Vsn} = application:get_key(amqp_client, vsn),
Default = [{<<"product">>, longstr, <<"RabbitMQ">>},
{<<"version">>, longstr, list_to_binary(Vsn)},
Expand Down
52 changes: 52 additions & 0 deletions src/amqp_sup.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
%% 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 the RabbitMQ Erlang Client.
%%
%% The Initial Developers of the Original Code are LShift Ltd.,
%% Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
%%
%% Portions created by LShift Ltd., Cohesive Financial
%% Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
%% 2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
%% Technologies Ltd.;
%%
%% All Rights Reserved.
%%
%% Contributor(s): ____________________.

%% @private
-module(amqp_sup).

-include("amqp_client.hrl").

-behaviour(supervisor2).

-export([start_link/0, start_connection_sup/2]).
-export([init/1]).

%%---------------------------------------------------------------------------
%% Interface
%%---------------------------------------------------------------------------

start_link() ->
supervisor2:start_link({local, amqp_sup}, ?MODULE, []).

start_connection_sup(Type, AmqpParams) ->
supervisor2:start_child(amqp_sup, [Type, AmqpParams]).

%%---------------------------------------------------------------------------
%% supervisor2 callbacks
%%---------------------------------------------------------------------------

init([]) ->
{ok, {{simple_one_for_one_terminate, 0, 1},
[{connection_sup, {amqp_connection_sup, start_link, []},
temporary, infinity, supervisor, [amqp_connection_sup]}]}}.
5 changes: 3 additions & 2 deletions test.mk
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ run_test_broker: start_test_broker_node unboot_broker
$$OK

start_test_broker_node: boot_broker
$(RABBITMQCTL) delete_user test_user_no_perm 2>/dev/null || true
sleep 1
- $(RABBITMQCTL) delete_user test_user_no_perm
$(RABBITMQCTL) add_user test_user_no_perm test_user_no_perm

stop_test_broker_node:
$(RABBITMQCTL) delete_user test_user_no_perm
- $(RABBITMQCTL) delete_user test_user_no_perm
$(MAKE) unboot_broker

boot_broker:
Expand Down

0 comments on commit 170d151

Please sign in to comment.