On 06/11/14 06:26, Richard Rodseth wrote:
I had in mind that I would strive to have a single var in my actors,
which was a reference to an immutable object.
One issue I've run into that since the actors go through various states
of initialization (using become), I find myself with bits of state which
can't be initialized in the constructor unless they're Options that can
be None. But then there's a bit of extra nuisance processing messages
down the line, when I *know* the option is a Some.
I could put some of this optional-because-available-later state in the
parameter list of receive() functions.
That's what I generally strive to do. If the state changes, it will be
by become-ing a new receive loop with the new state as an argument.
It works pretty well with the sole exception, at least in my experience,
of resources that need to be cleaned up in `postStop`. For that
particular case I need to use an instance member. It could still be a
`val`, but you might get an exception when you initialize that resource,
which means that the supervisor might need to override the
ActorInitializationException behaviour, which is to stop the supervised
actor.
Or I could just assert x.isdefined and assign x.get to a local val.
Or I could make my immutable model implement a trait with multiple
implementations (private case classes in the companion object say) where
the "later" state could have the valid references without any Option
wrapping. This assumes the logic in the receive block is delegated to
the model object.
Or ?
So I'm just curious what patterns might have worked well for others.
Thanks.
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> 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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
--
Ionuț G. Stan | http://igstan.ro
--
Read the docs: http://akka.io/docs/
Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
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/d/optout.