diff options
| author | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-02 11:57:38 +0100 |
|---|---|---|
| committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-02 11:57:38 +0100 |
| commit | 43420d3dc8a4eaa0d4be08ab5f63c110cb2ad640 (patch) | |
| tree | 1106cf972e973459772bf0b2f2852b93e31ef0d9 | |
| parent | c27fac485669a82f6ecd603d0edc811dd560e965 (diff) | |
| download | rabbitmq-server-git-43420d3dc8a4eaa0d4be08ab5f63c110cb2ad640.tar.gz | |
Make the channel and framing_channel more flexible in terms of being created. This improves the API to reduce special casing needed by the erlang client
| -rw-r--r-- | src/rabbit_channel.erl | 19 | ||||
| -rw-r--r-- | src/rabbit_channel_sup.erl | 7 | ||||
| -rw-r--r-- | src/rabbit_framing_channel.erl | 11 |
3 files changed, 13 insertions, 24 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 373cb6907d..58cb82f838 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -35,7 +35,7 @@ -behaviour(gen_server2). --export([start_link/5, start_link/6, do/2, do/3, shutdown/1]). +-export([start_link/6, do/2, do/3, shutdown/1]). -export([send_command/2, deliver/4, conserve_memory/2, flushed/2]). -export([list/0, info_keys/0, info/1, info/2, info_all/0, info_all/1]). @@ -75,12 +75,10 @@ -type(ref() :: any()). -type(channel_number() :: non_neg_integer()). +-type(pid_fun() :: fun (() -> pid())). --spec(start_link/5 :: - (channel_number(), pid(), rabbit_access_control:username(), - rabbit_types:vhost(), pid()) -> rabbit_types:ok(pid())). -spec(start_link/6 :: - (channel_number(), pid(), pid(), rabbit_access_control:username(), + (channel_number(), pid_fun(), pid_fun(), rabbit_access_control:username(), rabbit_types:vhost(), pid()) -> rabbit_types:ok(pid())). -spec(do/2 :: (pid(), rabbit_framing:amqp_method_record()) -> 'ok'). -spec(do/3 :: (pid(), rabbit_framing:amqp_method_record(), @@ -104,21 +102,14 @@ %%---------------------------------------------------------------------------- -start_link(Channel, ReaderPid, Username, VHost, CollectorPid) -> +start_link(Channel, GetReader, GetWriter, Username, VHost, CollectorPid) -> Parent = self(), {ok, proc_lib:spawn_link( fun () -> - WriterPid = rabbit_channel_sup:writer(Parent), - init_and_go([Channel, Parent, ReaderPid, WriterPid, + init_and_go([Channel, Parent, GetReader(), GetWriter(), Username, VHost, CollectorPid]) end)}. -start_link(Channel, ReaderPid, WriterPid, Username, VHost, CollectorPid) -> - Parent = self(), - {ok, proc_lib:spawn_link( - fun () -> init_and_go([Channel, Parent, ReaderPid, WriterPid, - Username, VHost, CollectorPid]) end)}. - do(Pid, Method) -> do(Pid, Method, none). diff --git a/src/rabbit_channel_sup.erl b/src/rabbit_channel_sup.erl index 0be7b5661c..eb7fab0de2 100644 --- a/src/rabbit_channel_sup.erl +++ b/src/rabbit_channel_sup.erl @@ -70,12 +70,15 @@ framing_channel(Pid) -> %%---------------------------------------------------------------------------- init([Sock, Channel, FrameMax, ReaderPid, Username, VHost, Collector]) -> + Me = self(), {ok, {{one_for_all, 0, 1}, - [{framing_channel, {rabbit_framing_channel, start_link, []}, + [{framing_channel, {rabbit_framing_channel, start_link, + [fun () -> channel(Me) end]}, permanent, ?MAX_WAIT, worker, [rabbit_framing_channel]}, {writer, {rabbit_writer, start_link, [Sock, Channel, FrameMax]}, permanent, ?MAX_WAIT, worker, [rabbit_writer]}, {channel, {rabbit_channel, start_link, - [Channel, ReaderPid, Username, VHost, Collector]}, + [Channel, fun () -> ReaderPid end, + fun () -> writer(Me) end, Username, VHost, Collector]}, permanent, ?MAX_WAIT, worker, [rabbit_channel]} ]}}. diff --git a/src/rabbit_framing_channel.erl b/src/rabbit_framing_channel.erl index 2e9f02a3e0..3a0d71f5f3 100644 --- a/src/rabbit_framing_channel.erl +++ b/src/rabbit_framing_channel.erl @@ -32,20 +32,15 @@ -module(rabbit_framing_channel). -include("rabbit.hrl"). --export([start_link/0, start_link/1, process/2, shutdown/1]). +-export([start_link/1, process/2, shutdown/1]). %% internal -export([mainloop/1]). %%-------------------------------------------------------------------- -start_link() -> - Parent = self(), - {ok, proc_lib:spawn_link( - fun () -> mainloop(rabbit_channel_sup:channel(Parent)) end)}. - -start_link(ChannelPid) -> - {ok, proc_lib:spawn_link(fun() -> mainloop(ChannelPid) end)}. +start_link(GetChannelPid) -> + {ok, proc_lib:spawn_link(fun () -> mainloop(GetChannelPid()) end)}. process(Pid, Frame) -> Pid ! {frame, Frame}, |
