Actor doesn't seem to manage State [Beginner Help]

I am new to Akka and to Scala and I built a small system to check whether a Sudoko configuration is valid: https://github.com/nsadeh/Sudoko/blob/master/src/main/scala/sudoko/Main.scala. It basically follows this guide: https://developer.lightbend.com/guides/akka-quickstart-scala/define-actors.html.

The issue right now is that the state of PartConstructor does not update, that is, it stays the empty state it is initialized in the whole time. I do not understand why, I am essentially following the same pattern as the Greeter bot actor in the example.

In the functional style of Akka, you manage your state by returning a Behavior with the new state. Note in the example:

else {
        message.from ! Greeter.Greet(message.whom, context.self)
        bot(n, max) //This is the important bit, it's returning a new Behavior with the new n value
      }

Also, the corresponding explanation:

Note how this Actor manages the counter by changing the behavior for each Greeted reply rather than using any variables. No concurrency guards such as synchronized or AtomicInteger are needed since an actor instance processes one message at a time.

Whereas, you are just returning Behavior.same

I can try to come up with a more detailed explanation over the weekend if this doesn’t make sense to you, but hopefully it can get you pointed in the right direction. Also note that if this is confusing to you, you can also adopt the objected oriented style as discussed here: Style guide • Akka Documentation . In that model, you keep your state in the object.

1 Like