• 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 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.
reply
    Bookmark Topic Watch Topic
  • New Topic