Effective Akka
by Jamie Allen
Copyright © 2013 Jamie Allen. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com.
Editor: Meghan Blanchette
Production Editor: Kara Ebrahim
Proofreader: Amanda Kersey
Cover Designer: Randy Comer
Interior Designer: David Futato
Illustrator: Rebecca Demarest
August 2013: First Edition
Revision History for the First Edition:
2013-08-15: First release
See http://oreilly.com/catalog/errata.csp?isbn=9781449360078 for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly
Media, Inc. Effective Akka, the image of a black grouse, and related trade dress are trademarks of O’Reilly
Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐
mark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no
responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.
ISBN: 978-1-449-36007-8
[LSI]
www.it-ebooks.info
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
1.
Actor Application Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Domain-driven 1
Domain-driven Messages Are “Facts” 2
Work Distribution 2
Routers and Routees 3
BalancingDispatcher Will Be Deprecated Soon! 7
Work Distribution Messages Are “Commands” 8
2.
Patterns of Actor Usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
The Extra Pattern 9
The Problem 9
Avoiding Ask 11
Capturing Context 12
Sending Yourself a Timeout Message 14
The Cameo Pattern 20
The Companion Object Factory Method 23
How to Test This Logic 23
3.
Best Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Actors Should Do Only One Thing 25
Single Responsibility Principle 25
Create Specific Supervisors 26
Keep the Error Kernel Simple 28
Failure Zones 29
Avoid Blocking 31
Futures Delegation Example 32
Pre-defining Parallel Futures 34
iii
www.it-ebooks.info