JavaOne 2012: Up, Up, and Out: Scaling Software with Akka

After the late-ending Community Keynote, I headed to Hilton Golden Gate 3/4/5 to see Viktor Klang‘s (Typesafe) ‘Up, Up and Out: Akka’ presentation. Klang is the technical lead on Akka. Akka is a ‘beautiful mountain in northern Sweden,’ is a Goddess, and is a Scala-based ‘toolkit and runtime for building highly concurrent, distributed, and fault tolerant event-driven applications on the JVM.’ Akka is not exclusive to Scala only and can be used ‘from Java today.’ Using Akka with Scala does allow you to do some things you cannot do with Akka when used with Java.

Akka is used by many large companies to solve real problems. Akka is built to scare in many directions and to provide extreme flexibility. One of Akka’s goals is to ‘manage system overload.’

Akka uses Actors: ‘Akka’s unit of code organization.’ According to Klang, ‘Actors help you create concurrent, scalable, and fault-tolerant applications.’ Actors ‘keep many ‘policy decisions’ separate from the business logic.’ Actors originated in 1970s (‘like all cool stuff in computer science’) and Erlang has been using actors with ‘great success’ for several years.

Klang warned to avoid ‘thinking in terms of shared state, a leaky abstraction.’ He added that threads and locks are ‘a means of execution’ rather than structural. He said this mixes execution with business logic. Concurrent collections are good optimizations for local uses.

Actors are ‘distributable by design’ and Klang had a slide listing several bullets explaining this statement. He stated that an actor can be an alternative to ‘a thread,’ ‘an object instance,’ ‘a callback or listener,’ ‘a singleton or service,’ ‘a router, load-balancer, or pool,’ ‘Java EE session bean or Message-Driven Bean,’ ‘out of process service,’ and ‘finite state machines.’

Klang referenced a video of Carl Hewitt on actors. An actor is a ‘fundamental unit of computation that embodies several key characteristics.’

Klang showed code examples in my preferred format in a presentation: embedded in his slides with color syntax highlighting. He showed step 0 (‘DEFINE’) in which his code defined the Actor’s class and the Actor’s behavior.

Once defined, the first operation (I – ‘CREATE’) ‘creates a new instance of an Actor.’ The created Actor is extremely lightweight and its ‘state and behavior are indistinguishable from each other.’ He drove this last point home: ‘The only way to observe state is by sending an actor a message and seeing how the actor reacts.’ The Actor is ‘very strong encapsulation’ of state, behavior, and message queue.

Akka provides an ActorSystem for creating Akka Actor instances. An instance of Props is provided to the Actor because actors need props.

Step 2 (‘SEND’) involves ‘sending a message to an Actor’ and ‘everything happens reactively’ and ‘everything is asynchronous and lockless.’ Akka supports a ‘fire and forget’ mode with the actor’s tell method. However, Akka provides guaranteed order of delivery. The reply is implemented in Akka with getSender().tell().

Step 3 (‘BECOME’) ‘redefines the Actor’s behavior’ and is ‘triggered reactively by receipt of message.’ The reasons one might want to change the behavior of an actor at runtime include supporting highly contended actor transforming to an actor pool or to implement graceful degradation.

Actors can supervise other Actors, leading to Step 4 (‘SUPERVISE’). A ‘supevisor detects and responds to the failures of the Actor(s) it supervises’ and Klang stated that this translates to ‘a clean separation and processing and error handling.’

Klang talked about ‘failure management in Java, C, and C#’ where you are ‘given a single thread of control.’ He put it this way in a bullet: ‘If this thread blows up, you are screwed.’ The implication of this is that all ‘explicit error handling’ is done ‘within the single thread’ and ‘tangled up’ with the business code.

Klang said the way to deal with error handling is to push the error handling out away from the business logic. He then referenced the onion-layer error kernel. Klang talked about callbacks (preRestart and postRestart) provided for Actors to handle failures.

A Router is a special case of Actor. Klang showed a slide with code using a RoundRobinRouter. He also showed being able to define the deployment scenario outside of the code in configuration file and referencing that from the code with a path. He took this example even further to show code for ‘remote deployment’ specifying a URL with the ‘akka’ protocol, a host name, and a port.

Everything that Klang presented to this point is available today as Akka 2.0. Klang said that there will be Akka Cluster in the to-be-released-soon Akka 2.1. He asked for feedback to ensure that the correct APIs and correct functionality are available for clustering in Akka 2.2. More information on Akka clustering is available in the specification, the user guide, and the code itself.

Akka 2.1 will also feature Akka Camel based on Apache Camel. The Typesafe Console is also available to monitor an Akka application and there is a live demo of this available.

Reference: JavaOne 2012: Up, Up, and Out: Scaling Software with Akka from our JCG partner Dustin Marx at the Inspired by Actual Events blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

One Response to "JavaOne 2012: Up, Up, and Out: Scaling Software with Akka"

  1. chamb says:

    “Akka is built to scare in many directions”. Works on me :)

Leave a Reply


1 × = four



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close