Think about what you are asking with when(_). Even if it did work it would
simply make all other when(..) irrelevant in the context of state
transitions within such FSM actor.
Now to some of your other points.
> ManagerFSM to create the child as long as the actor is preStarted
So, why not just override the preStart() method of an actor who is going to
be responsible for a child?
var childActor
override def preStart() {
childActor = context.actorOf(...)
}
or simply create a childActor during the construction of the parent actor
thus avoiding vars.
Having said that. . .
What is the purpose of the ManagerFSM and why do you believe it has to
manage someone else's children? IMHO its counterintuitive - children should
be managed by their parents otherwise they are not children. . . just
regular Actors;). (goes along with what Roland stated earlier)
Perhaps you could actually try to explain what exactly you are trying to
accomplish as a business use case since it seems like you may be making
things (architecture and design) more complex then they have to be.
Cheers
Oleg
On Wed, Feb 12, 2014 at 6:39 AM, Nader Aeinehchi <[email protected]>wrote:
> Hi Roland
>
> "sounds fishy, because actors do not expose methods, they only communicate
> via message passing"
> Agree. That is why I brought up this question.
>
> Let me try with an example:
>
> trait WorkerFSM[S, D] extends FSM[S, D]
> case class MyType // which can have subclasses to define different types
>
>
> trait ManagerFSM[S, D] extends FSM[S, D] {
>
> // here, "_" implies any state as long the actor is started and not stopped
> when(_){
> case(Event(MyType, _)){
> val myactor = context.actorOf[WorkerFSM[S,D]]("some name")
> sender ! myactor
> }}}
>
> The code above does not compile as I wrote in GMAIL.
>
> My problem is how to define "_" state as a wild card for all the states in
> the state machine.
>
> Thanks
> Nader
>
>
> On Wednesday, February 12, 2014 10:48:33 AM UTC+1, rkuhn wrote:
>
>> Hi Nader,
>>
>> I think it would be best if you demonstrated your problem with code; the
>> pseudo-code in the first email did not help me in this regard it seems.
>>
>> Just one thing: <<The manager class (ManagerFSM) exposes a method>> sounds
>> fishy, because actors do not expose methods, they only communicate via
>> message passing. The only thing you will see from the outside is the
>> ActorRef, which supports nothing besides the `tell` operation (which `ask`
>> is a variant of).
>>
>> Regards,
>>
>> Roland
>>
>> 12 feb 2014 kl. 09:08 skrev Nader Aeinehchi <[email protected]>:
>>
>> Hi again
>>
>> Let me explain it better. There are two options:
>>
>> 1. The manager class (ManagerFSM) exposes a method. Within the method,
>> we call context.actorOf(....). But such method is part of the actor and
>> NOT ActorRef. I do not know how to access such method from a client code.
>> Perhaps, I misunderstand something here?
>> 2. The second alternative is based on passing a Message to ManagerFSM.
>> Here, I struggle with FSM state handling mechanism. I cannot see an option
>> that sound "when(_){context.actorOf{...}".
>>
>> Perhaps, I misunderstand something here?
>>
>> In advance thank you very much.
>>
>> Best regards
>> Nader
>>
>>
>> On Tuesday, February 11, 2014 1:07:27 PM UTC+1, Akka Team wrote:
>>
>>> Hi Nader,
>>>
>>> it is not completely clear to me what you mean, especially by the "Does
>>> not work" comment. Within an FSM you can create child actors just like in
>>> any other actor, using "context.actorOf(...<props>..., name)". Child actors
>>> enjoy the same kind of encapsulation from all others--including from their
>>> parent--so you will need to send messages to communicate with them.
>>>
>>> Regards,
>>>
>>> Roland
>>>
>>>
>>>
>>> On Mon, Feb 10, 2014 at 10:24 PM, Nader Aeinehchi
>>> <[email protected]>wrote:
>>>
>>>> Hi
>>>>
>>>> How can a child actor (which itself implements FSM) be created and
>>>> added as a child to the context of a FSM actor?
>>>>
>>>> Suppose the following pseudocode:
>>>>
>>>> trait WorkerFSM[S, D] extends FSM[S, D]
>>>>
>>>> trait ManagerFSM[S, D] extends FSM[S, D] {
>>>>
>>>> // Does not work
>>>> // Create some WorkerFSM actor and add it to the children of this
>>>> ManagerFSM
>>>> def actorOf[w <: WorkerFSM[S, D]](name: String): FSM[S, D]
>>>> }
>>>>
>>>> The above does not work as only the reference to ActorRed is available
>>>> to the client code. In other words, the client code cannot access the
>>>> method "actorOf".
>>>>
>>>> One other alternative is to send messages to ManagerFSM. The problem
>>>> is that FSM is coupled to the given state using the construct
>>>> when(someState). But here, we would like ManagerFSM to create the child as
>>>> long as the actor is preStarted and not stopped (as dictated by Actor's
>>>> state diagram and not the fine-grained FSM state diagram).
>>>>
>>>> Any ideas?
>>>>
>>>> In advance, thank you very much.
>>>>
>>>> Nader
>>>>
>>>> --
>>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>> >>>>>>>>>> Search the archives: https://groups.google.com/
>>>> group/akka-user
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Akka User List" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at http://groups.google.com/group/akka-user.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>
>>>
>>> --
>>> Akka Team
>>> Typesafe - The software stack for applications that scale
>>> Blog: letitcrash.com
>>> Twitter: @akkateam
>>>
>>
>> --
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>>
>> *Dr. Roland Kuhn*
>> *Akka Tech Lead*
>> Typesafe <http://typesafe.com/> - Reactive apps on the JVM.
>> twitter: @rolandkuhn
>> <http://twitter.com/#!/rolandkuhn>
>>
>> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.