Book Image

Mastering Akka

By : Christian Baxter
Book Image

Mastering Akka

By: Christian Baxter

Overview of this book

For a programmer, writing multi-threaded applications is critical as it is important to break large tasks into smaller ones and run them simultaneously. Akka is a distributed computing toolkit that uses the abstraction of the Actor model, enabling developers to build correct, concurrent, and distributed applications using Java and Scala with ease. The book begins with a quick introduction that simplifies concurrent programming with actors. We then proceed to master all aspects of domain-driven design. We’ll teach you how to scale out with Akka Remoting/Clustering. Finally, we introduce Conductr as a means to deploy to and manage microservices across a cluster.
Table of Contents (17 chapters)
Mastering Akka
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface

Refactoring a bad actor to FSM


Now that we have recapped what actors are and understood some of the core features of the Akka actor system, it's time to dive in to our first big refactor. In the Chapter 1, Building a Better Reactive App, I called out the fact that the current implementation of the OrderManager was a poor use of an actor as it was mixing in too much usage of Futures.

This is a complicated actor, in that, it needs to fetch a bunch of data and then make various decisions on whether to stop or continue based on that data. When I end up with something like this, I usually turn to a finite-state machine (FSM) based actor. This is probably a different use case than what was originally intended or thought of as an FSM, but I think the state representations and transitions lend themselves nicely to complicated flows like this.

This actor will be modified a few more times before the book is done, with this being the first. You may find that some of the other refactors, such as to a...