This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Akka Actor Context Become in a Future result

 
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
I was trying out some Akka stuff where an Actor mutates state in a Future. Here is the complete source code!



When I tested the above, I get the following output:



Even though the counter is incremented in a Future, which eventually executes in a different thread, the order in which the increment happens is preserved and deterministic. Now I modified my receive method as below:



When I run the tests now, the order of increment is non-deterministic:



What I don't get is what effect the context become has on mutating the state of the actor?
 
Ranch Hand
Posts: 125
Scala Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
context become is just used to switch actor's behavior at runtime.

Upon arrival of any message on MutableStateActor, the receive block changes MutableStateActor's behavior to mutableReceiver, and now the MutableStateActor can only understand messages of type Increment and CounterStatus until unbecome.

As per my understanding become doesn't have any effect in mutating the state of the actor in terms of the counter. You may want to try both piece of code with a bigger set of increments to come to a conclusion.


Edited:
Just for the sake of it, I ran the Actor from the first snippet of code and got the following output:


You can clearly see that the state is still non-deterministic.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic