Skip to main content

Actors in Java : Introduction

Posted by jcmansigian on October 8, 2013 at 1:38 AM PDT

   This is the first in a series of posts about the actor model of computation in Java. This series of posts will cover many aspects of actors from a Java perspective. First a brief explanation of what the actor model is. Actors are stateful units of computation that obey the discipline of exposing their internal state to other actors only through information contained in messages they exchange with each other. The original conception of actors by computer scientist Carl Hewitt included hardware as well as software implementations. The actors of this discussion will all be implemented in software. The Java Virtual Machine is the most capable platform hosting actors today and will serve as the platform for all examples of actor behavior in this series.

   A group of actors are organized into a community called an actor system which addresses a common purpose . Actors within the same actor system may all be located on the same machine or they may be geographically dispersed across a network. An actor can communicate with other actors, both within and outside of its own actor system, only if the actor knows the message recipient's address called the actor path, or simply the path. An actor has exactly two ways of knowing the path to another actor; by creating the actor itself or by being told the path of the actor. Actors within an actor system are typically organized into a hierarchical structure with one or more top level actors being the creators of child actors who themselves can be creators of child actors. The creation hierarchy mirrors a pattern of supervision and control within an actor system. For example a failing child actor can be replaced with a fresh instance and restarted by its parent. Actors can be deployed locally or remotely by a parent actor who can reside anywhere that has connectivity with the host of the child actor being created.

   The actor model falls within the broader object oriented paradigm. It is a more disciplined approach to the management of state than the mainstream practice of object oriented programming. In terms of its philosophy about statefulnes the actor model falls between the purest form of functional programming which abhors statefulnes altogether and traditional object oriented programming that allows variables to be mutable but has mechanisms that restrict access. The actor model is stricter than traditional object oriented programming but not as strict as pure functional programming with regards to statefulnes and its management.

The next post in this series will be “Actors in Java : What are they good for?”