<div dir="ltr">I didn't indicate an error because there wasn't any. Even with SASL started. <br><br>My problem is that I didn't realize that FSMs were event based. I did realize they could handle events, but didn't realize that's how they are supposed to be used. I thought that at the end of each state function, it would change state (which it does do) and then call the next state function automatically.<br>
<br>Since FSMs don't work like that, I switched to a good old fashioned process with spawn_link and my project is making headway.<br><br>Thank you both very much for your help!<br><br><div class="gmail_quote">On Wed, Aug 20, 2008 at 6:06 PM, Serge Aleynikov <span dir="ltr"><<a href="mailto:saleyn@gmail.com">saleyn@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">After looking at your code for the second time, I see that the init function is wrong - it should be:<br>
<br>
init([StartArgs]) -><br>
...<br>
<br>
Try that. You are not indicating here what the error is, but if it is function_clause, then that's it.<br><font color="#888888">
<br>
Serge</font><div><div></div><div class="Wj3C7c"><br>
<br>
Matt Williamson wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
So no. I did not send it any event.<br>
Serge, I enabled sasl via application:start/1 but when I ran the function in<br>
question I didn't get any output from it.<br>
<br>
On Wed, Aug 20, 2008 at 1:00 PM, Mazen Harake<br>
<<a href="mailto:mazen@erlang-consulting.com" target="_blank">mazen@erlang-consulting.com</a>>wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Matt,<br>
<br>
Sorry this might be a stupid question but did you send it an event?<br>
<br>
/Mazen<br>
<br>
Matt Williamson wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I hate to keep bugging with simple problems, but I'm stuck again. My FSM<br>
dosn't seem to be executing its first state. Here is my init function:<br>
<br>
/init(StartArgs) -><br>
InitialState = case StartArgs of<br>
{store_chunk, Chunk} -><br>
io:format("FSM Storing chunk...~n"),<br>
{ok, storing_chunk, [Chunk]};<br>
{get_chunk, Args} -><br>
{ok, getting_chunk, Args};<br>
Else -><br>
%% @todo Add error logging here.<br>
io:format("Bad arg for FSM: ~p~n", [StartArgs])<br>
end,<br>
io:format("FSM Initial State: ~p~n", [InitialState]),<br>
InitialState./<br>
<br>
storing_chunk/2 is exported and I'm not getting any errors. Here is that<br>
function:<br>
<br>
/storing_chunk(_Event, [Chunk]) -><br>
io:format("STATE: storing_chunk~n"),<br>
case erlfs_store_lib:store_chunk() of<br>
ok -><br>
{next_state, notifying_tracker, Chunk};<br>
{error, Reason} -><br>
%% @todo Add error logging here.<br>
io:format("FSM Stopped: ~p~n", [Reason]),<br>
{stop, {file, Reason}, Chunk#chunk.chunk_meta}<br>
end./<br>
<br>
On Wed, Aug 20, 2008 at 11:04 AM, Serge Aleynikov <<a href="mailto:saleyn@gmail.com" target="_blank">saleyn@gmail.com</a><mailto:<br>
<a href="mailto:saleyn@gmail.com" target="_blank">saleyn@gmail.com</a>>> wrote:<br>
<br>
The error you reported earlier:<br>
<br>
{'EXIT', {badarg, [{erlang, apply,<br>
[erlfs_store_worker_fsm, start_link, {store_chunk, ...}]}]}}<br>
<br>
was a clear indication that erlang:apply(M,F,A) was called with A<br>
being a tuple rather than a list. If this still doesn't work<br>
after replacing tuple with a list in the second argument of the<br>
supervisor:start_child/2 call, this means that you probably have<br>
other issues in the erlfs_store_worker_fsm:start_link/1 itself.<br>
<br>
I can't say anything more without seeing a more detailed error report.<br>
<br>
Serge<br>
<br>
<br>
Matt Williamson wrote:<br>
<br>
Yes, I saw that in the docs. What I was saying is that calling<br>
apply(M, F,<br>
A++List) =:= apply(M, F, List) when A =:= [].<br>
<br>
I did try your suggestion anyway with the same results.<br>
<br>
On Wed, Aug 20, 2008 at 9:54 AM, Serge Aleynikov<br>
<<a href="mailto:saleyn@gmail.com" target="_blank">saleyn@gmail.com</a> <mailto:<a href="mailto:saleyn@gmail.com" target="_blank">saleyn@gmail.com</a>>> wrote:<br>
<br>
What is the arity of erlfs_store_worker_fsm:start_link<br>
function?<br>
<br>
Not quite sure what you mean by [] ++ 1 below.<br>
<br>
The supervisor:start_child/2 takes a list [term()] as the<br>
second parameter.<br>
Here's its docs:<br>
<br>
"If the case of a simple_one_for_one supervisor, the child<br>
specification<br>
defined in Module:init/1 will be used and ChildSpec should<br>
instead be an<br>
arbitrary list of terms List. The child process will then<br>
be started by<br>
appending List to the existing start function arguments,<br>
i.e. by calling<br>
apply(M, F, A++List) where {M,F,A} is the start function<br>
defined in the<br>
child specification."<br>
<br>
Note the A++List part.<br>
<br>
<br>
Matt Williamson wrote:<br>
<br>
I'm afraid that did not work. I am passing an empty<br>
list, and if I execute<br>
[] ++ 1 in the shell I get 1.<br>
<br>
On Wed, Aug 20, 2008 at 9:31 AM, Serge Aleynikov<br>
<<a href="mailto:saleyn@gmail.com" target="_blank">saleyn@gmail.com</a> <mailto:<a href="mailto:saleyn@gmail.com" target="_blank">saleyn@gmail.com</a>>><br>
<br>
wrote:<br>
<br>
Try starting it as:<br>
<br>
supervisor:start_child(erlfs_store_worker_sup,<br>
[{store_chunk, Chunk}])<br>
<br>
The simple_one_for_one strategy appends the<br>
arguments passed to<br>
supervisor:start_child/2 to the list of args<br>
specified in the<br>
supervisor's<br>
spec.<br>
<br>
Serge<br>
<br>
Matt Williamson wrote:<br>
<br>
Hello,<br>
<br>
I am starting a gen_fsm with<br>
supervisor:start_child(erlfs_store_worker_sup,<br>
{store_chunk, Chunk}) but I get the following<br>
error:<br>
<br>
{error,<br>
{'EXIT',<br>
{badarg,<br>
[{erlang,<br>
apply,<br>
<br>
[erlfs_store_worker_fsm,<br>
start_link,<br>
{store_chunk,<br>
{chunk,<br>
<br>
{chunk_meta,<br>
<br>
{file_meta,<br>
<br>
"test123",<br>
<br>
"test.txt",<br>
0,<br>
<br>
"text/plain",<br>
<br>
{{0,1,1},{0,0,0}}},<br>
0,<br>
0,<br>
[]},<br>
<br>
<<"Hello world!">>}}]},<br>
<br>
{supervisor,do_start_child_i,3},<br>
<br>
{supervisor,handle_call,3},<br>
<br>
{gen_server,handle_msg,6},<br>
<br>
{proc_lib,init_p,5}]}}}<br>
<br>
I've been trying to figure it out for a while,<br>
but I am having a hard<br>
time.<br>
Here is the Child Spec in the supervisor<br>
(erlfs_store_worker_sup):<br>
<br>
init(Args) -><br>
WorkerSpec = {erlfs_store_worker_fsm,<br>
{erlfs_store_worker_fsm,<br>
start_link, []},<br>
temporary, 2000, worker,<br>
[erlfs_store_worker_fsm]},<br>
{ok,{{simple_one_for_one, 0, 1}, [WorkerSpec]}}.<br>
<br>
<br>
<br>
<br>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<mailto:<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a>><br>
<br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
<br>
<br>
<br>
<br>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
</blockquote>
<br>
--<br>
Mazen Harake <<a href="mailto:mazen@erlang-consulting.com" target="_blank">mazen@erlang-consulting.com</a>><br>
Erlang Software Developer and Consultant,<br>
Erlang Training & Consulting, Ltd<br>
<br>
Mobile Phone: +44 (0)795 13 26 317<br>
Office Phone: +44 (0)207 45 61 020<br>
Office Address:<br>
401 London Fruit & Wool Exchange<br>
Brushfield St, London, E1 6EL<br>
United Kingdom<br>
<br>
This email and its attachments may be confidential and are intended solely<br>
for the use of the individual to whom it is addressed. Any views or opinions<br>
expressed are solely those of the author and do not necessarily represent<br>
those of "Erlang Training & Consulting, Ltd".<br>
<br>
If you are not the intended recipient of this email and its attachments,<br>
you must take no action based upon them, nor must you copy or show them to<br>
anyone. Please contact the sender if you believe you have received this<br>
email in error.<br>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>