• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Akka actor avoid mutating state

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very recently, I read about distributed actors or remote actors (whatever you call it). I have been comfortable so far using state in my Actor and mutate it inside my receive method. Happy days! Now I want to distribute my actor across several JVM's and I already see that my state in my actor could be an issue.

I did read about the become and unbecome and I was just wondering how Akka handles this internally? Any ideas? Here is a small example:



Now, when I call the TestActor in the following sequence:


Initializes the actor, calls the default receive method which calls the starter method and in the starter method case Add matches and the starter now becomes the default receive method for the next subsequent messages! My question is, where is the mutated List maintained?


 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the solution that I was looking for!

http://stackoverflow.com/questions/28049636/akka-actor-avoiding-mutating-state
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's some more stuff that might be useful.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I picked up the example from that GitHub post! I wanted to have a much detailed know how on where the state is handled! Frankly speaking I'm not so impressed with the become / unbecome. It just hides the state away in my actor to appear within the context of become / unbecome. How is this supposed to be better? If you look at the Stackoverflow post, it clearly shows that the state is evaluated as the result of the function in the stack!
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Might be having state on the stack is cheaper than having it on the heap!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic