I sometimes use a single var containing an immutable model. Remember that
you don't have to worry about synchronization and locks, so multiple vars
may not be the end of the world.
I also use the become(state) technique.
Also look into the FSM trait.
http://doc.akka.io/docs/akka/snapshot/scala/fsm.html

On Mon, Aug 10, 2015 at 7:16 AM, <lalge...@gmail.com> wrote:

> Actors typcially required state that are var-declarations.; e.g., to hold
> a sum in an accumulator. What's the best way to do this without
> var-declarations?
>
> One that comes to mind is to keep 'becoming' a new behavior as shown
> below. Is this efficient? Is there a pattern to write the *receive *method
> without the auxillary *morph *method?
>
> Enter code here...
> class FunctionalActor(val sum: Int) extends Actor {
>     def morph(sum: Int) : Receive = {
>         case "inc" =>
>             context.become(morph(sum+1))
>         case "report" =>
>             sender() ! sum
>             context.become(morph(0))
>     }
>
>     def receive : Receive = morph(sum)
> }
>
> Thanks.
>
> Lal
>
> --
> >>>>>>>>>> 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 akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to