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