Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 174 lines (143 sloc) 6.997 kb
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
1 %%% This code was developped by IDEALX (http://IDEALX.org/) and
2 %%% contributors (their names can be found in the CONTRIBUTORS file).
3 %%% Copyright (C) 2000-2001 IDEALX
4 %%%
5 %%% This program is free software; you can redistribute it and/or modify
6 %%% it under the terms of the GNU General Public License as published by
7 %%% the Free Software Foundation; either version 2 of the License, or
8 %%% (at your option) any later version.
9 %%%
10 %%% This program is distributed in the hope that it will be useful,
11 %%% but WITHOUT ANY WARRANTY; without even the implied warranty of
12 %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 %%% GNU General Public License for more details.
14 %%%
15 %%% You should have received a copy of the GNU General Public License
16 %%% along with this program; if not, write to the Free Software
17 %%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
18 %%%
5d10a86 @nniclausse add explicit exception in the GPL for linking EPL modules (obvious, b…
nniclausse authored
19 %%% In addition, as a special exception, you have the permission to
20 %%% link the code of this program with any library released under
21 %%% the EPL license and distribute linked combinations including
22 %%% the two.
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
23
24 -module(ts_timer).
25 -vc('$Id$ ').
26 -author('jflecomte@IDEALX.com').
41e965d @nniclausse update email
nniclausse authored
27 -modifiedby('nicolas@niclux.org').
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
28
583ea5e @nniclausse put macros in a separated header file; add NOW macro
nniclausse authored
29 -include("ts_macros.hrl").
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
30
31 -behaviour(gen_fsm).
32
33 %% Puropose:
47eafd9 @nniclausse make jabber work again (more or less; not tested with a real server)
nniclausse authored
34 %% gen_fsm with 3 states: receiver, ack, initialize
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
35 %% External events: connected
36
37 %% External exports
47eafd9 @nniclausse make jabber work again (more or less; not tested with a real server)
nniclausse authored
38 -export([start/1, connected/1, config/1]).
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
39
40 %% gen_fsm callbacks
47eafd9 @nniclausse make jabber work again (more or less; not tested with a real server)
nniclausse authored
41 -export([init/1, initialize/2, receiver/2, ack/2, handle_event/3,
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
42 handle_sync_event/4, handle_info/3, terminate/3, code_change/4]).
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
43
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
44 -record(state, {nclient=0, pidlist = []}).
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
45
46 %%%----------------------------------------------------------------------
47 %%% API
48 %%%----------------------------------------------------------------------
49 start(NClients) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
50 ?LOG("starting fsm timer",?INFO),
51 gen_fsm:start_link({global, ?MODULE}, ?MODULE, [NClients], []).
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
52
47eafd9 @nniclausse make jabber work again (more or less; not tested with a real server)
nniclausse authored
53 config(NClients) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
54 ?LOG("Configure fsm timer",?INFO),
55 gen_fsm:send_event({global, ?MODULE}, {config, NClients}).
47eafd9 @nniclausse make jabber work again (more or less; not tested with a real server)
nniclausse authored
56
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
57 connected(Pid) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
58 gen_fsm:send_event({global, ?MODULE}, {connected, Pid}).
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
59
60 %%%----------------------------------------------------------------------
61 %%% Callback functions from gen_fsm
62 %%%----------------------------------------------------------------------
63
64 %%----------------------------------------------------------------------
65 %% Func: init/1
66 %% Returns: {ok, StateName, StateData} |
67 %% {ok, StateName, StateData, Timeout} |
68 %% ignore |
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
69 %% {stop, StopReason}
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
70 %%----------------------------------------------------------------------
7ed8fc3 @nniclausse forgot to add the last pid
nniclausse authored
71 init(_Args) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
72 ?LOG("starting timer",?INFO),
73 {ok, initialize, #state{}}.
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
74
75 %%----------------------------------------------------------------------
76 %% Func: StateName/2
77 %% Returns: {next_state, NextStateName, NextStateData} |
78 %% {next_state, NextStateName, NextStateData, Timeout} |
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
79 %% {stop, Reason, NewStateData}
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
80 %%----------------------------------------------------------------------
47eafd9 @nniclausse make jabber work again (more or less; not tested with a real server)
nniclausse authored
81 initialize({config, Val}, State) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
82 {next_state, receiver, State#state{nclient=Val}}.
47eafd9 @nniclausse make jabber work again (more or less; not tested with a real server)
nniclausse authored
83
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
84
85 %% now all the clients are connected, let's start to ack them
f23f4d5 @nniclausse fix client count; more debugging msg
nniclausse authored
86 receiver({connected, Pid}, #state{pidlist=List, nclient=1}) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
87 ?LOG("All connected, global ack!",?NOTICE),
88 {next_state, ack, #state{pidlist=[Pid|List],nclient=0}, 1};
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
89
90 %% receive a new connected mes
91 receiver({connected, Pid}, #state{pidlist=List, nclient=N}) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
92 ?LOGF("New connected ~p (nclient=~p)",[Pid, N],?DEB),
93 {next_state, receiver, #state{pidlist=List ++ [Pid], nclient=N-1},
94 ?config(clients_timeout)};
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
95
96 %% timeout event, now we start to send ack, by sending a timeout event immediatly
97 receiver(timeout, StateData) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
98 {next_state, ack, StateData,1}.
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
99
100 %% no more ack to send, stop
101 ack(timeout, #state{pidlist=[]}) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
102 {stop, normal, #state{}};
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
103
8ac455b @nniclausse -add function for Debug message only (not executed unless compiled wi…
nniclausse authored
104 %% ack all pids
105 ack(timeout, #state{pidlist=L}) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
106 lists:foreach(fun(A)->ts_client:next({A}) end, L),
107 {next_state, receiver, #state{pidlist=[]}}.
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
108
109 %%----------------------------------------------------------------------
110 %% Func: StateName/3
111 %% Returns: {next_state, NextStateName, NextStateData} |
112 %% {next_state, NextStateName, NextStateData, Timeout} |
113 %% {reply, Reply, NextStateName, NextStateData} |
114 %% {reply, Reply, NextStateName, NextStateData, Timeout} |
115 %% {stop, Reason, NewStateData} |
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
116 %% {stop, Reason, Reply, NewStateData}
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
117 %%----------------------------------------------------------------------
118
119
120 %%----------------------------------------------------------------------
121 %% Func: handle_event/3
122 %% Returns: {next_state, NextStateName, NextStateData} |
123 %% {next_state, NextStateName, NextStateData, Timeout} |
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
124 %% {stop, Reason, NewStateData}
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
125 %%----------------------------------------------------------------------
e351280 @nniclausse avoid warnings for unused variables
nniclausse authored
126 handle_event(_Event, StateName, StateData) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
127 {next_state, StateName, StateData}.
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
128
129 %%----------------------------------------------------------------------
130 %% Func: handle_sync_event/4
131 %% Returns: {next_state, NextStateName, NextStateData} |
132 %% {next_state, NextStateName, NextStateData, Timeout} |
133 %% {reply, Reply, NextStateName, NextStateData} |
134 %% {reply, Reply, NextStateName, NextStateData, Timeout} |
135 %% {stop, Reason, NewStateData} |
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
136 %% {stop, Reason, Reply, NewStateData}
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
137 %%----------------------------------------------------------------------
e351280 @nniclausse avoid warnings for unused variables
nniclausse authored
138 handle_sync_event(_Event, _From, StateName, StateData) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
139 Reply = ok,
140 {reply, Reply, StateName, StateData}.
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
141
142 %%----------------------------------------------------------------------
143 %% Func: handle_info/3
144 %% Returns: {next_state, NextStateName, NextStateData} |
145 %% {next_state, NextStateName, NextStateData, Timeout} |
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
146 %% {stop, Reason, NewStateData}
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
147 %%----------------------------------------------------------------------
e351280 @nniclausse avoid warnings for unused variables
nniclausse authored
148 handle_info(_Info, StateName, StateData) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
149 {next_state, StateName, StateData}.
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
150
151 %%----------------------------------------------------------------------
152 %% Func: terminate/3
153 %% Purpose: Shutdown the fsm
154 %% Returns: any
155 %%----------------------------------------------------------------------
e351280 @nniclausse avoid warnings for unused variables
nniclausse authored
156 terminate(_Reason, _StateName, _StateData) ->
7c78d58 @nniclausse add wait_global thinktime (TSUN-165)
nniclausse authored
157 ?LOG("terminate timer",?INFO),
158 ok.
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
159
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
160 %%--------------------------------------------------------------------
161 %% Func: code_change/4
162 %% Purpose: Convert process state when code is changed
163 %% Returns: {ok, NewState, NewStateData}
164 %%--------------------------------------------------------------------
e351280 @nniclausse avoid warnings for unused variables
nniclausse authored
165 code_change(_OldVsn, StateName, StateData, _Extra) ->
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
166 {ok, StateName, StateData}.
167
da16c35 @nniclausse import version publique du client de test de mont�e en charge.
nniclausse authored
168 %%%----------------------------------------------------------------------
169 %%% Internal functions
170 %%%----------------------------------------------------------------------
171
172
173
Something went wrong with that request. Please try again.