Actor Model implementation for building concurrent, distributed, fault-tolerant applications
npx @tessl/cli install tessl/maven-com-typesafe-akka--akka-actor_2-12@2.8.0Akka Actor is a powerful toolkit for building highly concurrent, distributed, and resilient message-driven applications on the JVM. It provides an implementation of the Actor Model, where actors are the fundamental units of computation that communicate through asynchronous message passing.
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
<version>2.8.8</version>
</dependency>libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.8.8"import akka.actor._
import akka.pattern._
import akka.util.Timeout
import scala.concurrent.duration._
import scala.concurrent.Future
```{ .api }
## Basic Usage
### Creating an Actor System
```scala
import akka.actor.ActorSystem
val system = ActorSystem("MySystem")
```{ .api }
### Creating a Simple Actor
```scala
import akka.actor.{Actor, ActorRef, ActorSystem, Props}
class HelloActor extends Actor {
def receive = {
case "hello" => sender() ! "Hello back to you"
case msg => println(s"Unknown message: $msg")
}
}
val system = ActorSystem("HelloSystem")
val helloActor = system.actorOf(Props[HelloActor](), "hello-actor")
// Send a message (fire-and-forget)
helloActor ! "hello"
```{ .api }
### Actor with Constructor Parameters
```scala
class GreetingActor(greeting: String) extends Actor {
def receive = {
case name: String => sender() ! s"$greeting, $name!"
}
}
val greetingActor = system.actorOf(Props(new GreetingActor("Hello")), "greeting-actor")
```{ .api }
### Request-Response with Ask Pattern
```scala
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import scala.concurrent.Future
implicit val timeout: Timeout = 5.seconds
implicit val ec = system.dispatcher
val future: Future[Any] = helloActor ? "hello"
future.foreach(println)
```{ .api }
## Architecture Overview
### Core Components
- **Actor**: The fundamental unit of computation that processes messages sequentially
- **ActorRef**: Immutable handle to an actor that enables message sending
- **ActorSystem**: Factory for actors and runtime for actor execution
- **Props**: Configuration object for creating actors (immutable and thread-safe)
- **ActorContext**: Context available to actors during message processing
### Actor Hierarchy
Actors are organized in a hierarchical structure where each actor has a parent (except the root guardian) and can create child actors. This hierarchy provides supervision and fault isolation.ActorSystem ├── /user (user guardian) │ ├── /user/my-actor │ └── /user/another-actor │ └── /user/another-actor/child-actor └── /system (system guardian) ├── /system/deadLetters ├── /system/log └── ...
## Key Features
- **Location Transparency**: Actors can be local or remote without code changes
- **Fault Tolerance**: Supervisors handle actor failures automatically
- **Concurrency**: Actors process messages sequentially, avoiding shared mutable state
- **Scalability**: Millions of actors can exist in a single application
- **Message Routing**: Flexible message routing and load balancing
- **Finite State Machines**: Built-in FSM support for stateful actors
## Documentation Sections
### [Core Actors](core-actors.md)
Comprehensive coverage of the core actor classes and interfaces including `Actor`, `AbstractActor`, `ActorRef`, `Props`, and `ActorSystem`. Learn how to create, configure, and manage actors.
### [Actor Lifecycle](actor-lifecycle.md)
Actor lifecycle management, supervision strategies, fault tolerance mechanisms, and the actor restart process. Understanding how actors are born, supervised, and terminated.
### [Routing](routing.md)
Router configurations, routing strategies, and load balancing. Learn about round-robin, random, smallest mailbox, and other routing algorithms for distributing messages across multiple actors.
### [Patterns](patterns.md)
Common actor patterns including the ask pattern for request-response, pipeTo for forwarding Future results, graceful shutdown procedures, and other essential patterns.
### [FSM (Finite State Machines)](fsm.md)
Built-in finite state machine support for creating stateful actors that transition between different states based on events and conditions.
### [Messaging](messaging.md)
Message types, actor selection, addressing, dead letters, and communication patterns. Understanding how actors find and communicate with each other.
### [Scheduling](scheduling.md)
Scheduling operations, timers, timeout handling, and periodic tasks. Learn how to schedule work in the actor system.
### [I/O & Networking](io-networking.md)
Network I/O operations, TCP and UDP support, and integration with Akka I/O for building networked applications.
## Quick Reference
### Essential Actor Methods
```scala
// In Actor trait
def receive: Receive // Abstract method for message handling
def sender(): ActorRef // Sender of current message
def context: ActorContext // Actor context
def self: ActorRef // Reference to this actor
```{ .api }
### Essential ActorRef Methods
```scala
// Sending messages
actorRef ! message // Fire-and-forget
actorRef.tell(message, sender) // With explicit sender
actorRef.forward(message) // Forward with original sender
```{ .api }
### Essential ActorSystem Methods
```scala
// Creating actors
system.actorOf(props, "name") // Create top-level actor
system.stop(actorRef) // Stop an actor
system.terminate() // Shutdown actor system
```{ .api }
### Essential ActorContext Methods
```scala
// In actor
context.actorOf(props, "child") // Create child actor
context.stop(actorRef) // Stop child actor
context.watch(actorRef) // Watch for termination
context.become(newBehavior) // Change behavior
```{ .api }
This comprehensive documentation covers all aspects of the Akka Actor library, from basic usage to advanced patterns and configurations. Each section provides detailed API documentation with practical examples.