Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Makes the drain buffer size configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
archaelus committed Jun 13, 2012
1 parent 829f9cf commit 9621fed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/logplex.app.src
Expand Up @@ -24,6 +24,7 @@
,{tcp_syslog_send_loss_msg, send} % send | dont_send
,{syslog_port, 6001} % tcp port
,{max_drains_per_channel, 5} % #channels
,{drain_buffer_size, 1024} % #messages
]}
]}.

31 changes: 21 additions & 10 deletions src/logplex_drain_buffer.erl
Expand Up @@ -14,6 +14,7 @@
-include_lib("eunit/include/eunit.hrl").

-record(state, {buf = logplex_msg_buffer:new() :: logplex_msg_buffer:buf(),
buf_size = 1024 :: logplex_msg_buffer:size(),
channel_id :: logplex_channel:id(),
owner :: pid(),
on_activation :: 'undefined' |
Expand All @@ -36,7 +37,7 @@

-export([start_link/2
,start_link/1
,start_link/3
,start_link/4
,set_active/3
,notify/1
]).
Expand Down Expand Up @@ -65,25 +66,34 @@ start_link(ChannelId) ->
start_link(ChannelId, self()).

start_link(ChannelId, Owner) ->
start_link(ChannelId, Owner, notify).
start_link(ChannelId, Owner, notify,
logplex_app:config(drain_buffer_size, 1024)).

-spec start_link(ChannelId::logplex_channel:id(),
Owner::pid(),
{active, TargBytes::pos_integer(),
Fun::logplex_msg_buffer:framing_fun()} |
'passive' | 'notify') -> any().
start_link(ChannelId, Owner, {active, TargBytes, Fun})
when is_integer(TargBytes), TargBytes > 0,
is_function(Fun, 1) ->
'passive' | 'notify', Size::pos_integer()) -> any().
start_link(ChannelId, Owner, {active, TargBytes, Fun}, Size)
when is_integer(ChannelId),
is_pid(Owner),
is_integer(TargBytes), TargBytes > 0,
is_function(Fun, 1),
is_integer(Size), Size > 0 ->
gen_fsm:start_link(?MODULE, {active,
#state{channel_id = ChannelId,
owner = Owner,
buf_size = Size,
on_activation = {TargBytes, Fun}}}, []);
start_link(ChannelId, Owner, Mode)
when Mode =:= passive; Mode =:= notify ->
start_link(ChannelId, Owner, Mode, Size)
when is_integer(ChannelId),
is_pid(Owner),
Mode =:= passive orelse Mode =:= notify,
is_integer(Size), Size > 0 ->
gen_fsm:start_link(?MODULE, {Mode,
#state{channel_id = ChannelId,
owner = Owner,
buf_size = Size,
on_activation = undefined}}, []).


Expand All @@ -109,11 +119,12 @@ post(Buffer, Msg) ->

%% @private
init({Mode, S = #state{channel_id = ChannelId,
owner = Owner}})
owner = Owner,
buf_size = Size}})
when Mode =:= notify orelse Mode =:= passive,
is_pid(Owner), is_integer(ChannelId) ->
logplex_channel:register({channel, ChannelId}),
{ok, Mode, S}.
{ok, Mode, S#state{buf = logplex_msg_buffer:new(Size)}}.


%% @private
Expand Down

0 comments on commit 9621fed

Please sign in to comment.