CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-typesafe-akka--akka-actor-2-13

Akka Actor library - a toolkit for building highly concurrent, distributed, and resilient message-driven applications for Java and Scala using the Actor Model.

Overview
Eval results
Files

actor-system.mddocs/

Actor System Management

The ActorSystem is the root container that manages actor hierarchies, configuration, and system services. It provides the foundation for creating and managing actors, along with essential services like event streaming, scheduling, and dispatching.

Capabilities

ActorSystem Creation and Configuration

Creates and configures actor systems with various options for name, configuration, and classloader.

/**
 * Abstract base class for actor systems providing core functionality
 */
abstract class ActorSystem extends ActorRefFactory with ClassicActorSystemProvider {
  /** The name of this actor system */
  def name: String
  
  /** The configuration settings for this system */
  def settings: Settings
  
  /** The event stream for system-wide event publishing */
  def eventStream: EventStream
  
  /** The scheduler for delayed and periodic tasks */
  def scheduler: Scheduler
  
  /** The dispatcher registry for message processing */
  def dispatchers: Dispatchers
  
  /** The log instance for this system */
  def log: LoggingAdapter
  
  /** The uptime of this system in milliseconds */
  def uptime: Long
  
  /** The start time of this system */
  def startTime: Long
  
  /** Terminates this actor system gracefully */
  def terminate(): Future[Terminated]
  
  /** Future that completes when the system has terminated */
  def whenTerminated: Future[Terminated]
}

object ActorSystem {
  /** Create an ActorSystem with default name and configuration */
  def create(): ActorSystem
  
  /** Create an ActorSystem with specified name */
  def create(name: String): ActorSystem
  
  /** Create an ActorSystem with specified name and configuration */
  def create(name: String, config: Config): ActorSystem
  
  /** Create an ActorSystem with name, config, and classloader */
  def create(name: String, config: Config, classLoader: ClassLoader): ActorSystem
  
  /** Create an ActorSystem with name, config, classloader, and executor */
  def create(name: String, config: Config, classLoader: ClassLoader, defaultExecutionContext: Option[ExecutionContext]): ActorSystem
  
  // Scala API methods
  def apply(): ActorSystem
  def apply(name: String): ActorSystem  
  def apply(name: String, config: Config): ActorSystem
  def apply(name: String, config: Config, classLoader: ClassLoader): ActorSystem
  def apply(name: String, config: Config, classLoader: ClassLoader, defaultExecutionContext: Option[ExecutionContext]): ActorSystem
}

Usage Examples:

import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory

// Create with default settings
val system = ActorSystem("MySystem")

// Create with custom configuration
val config = ConfigFactory.parseString("""
  akka {
    actor {
      provider = "local"
      default-dispatcher {
        throughput = 1
      }
    }
  }
""")
val configuredSystem = ActorSystem("ConfiguredSystem", config)

// Shutdown system
system.terminate()

System Settings and Configuration

Access and manage system configuration settings.

/**
 * System configuration settings
 */
class Settings(cfg: Config, name: String, classLoader: ClassLoader) {
  /** The configuration object backing this settings */
  val config: Config = cfg
  
  /** The name of the actor system */
  val name: String
  
  /** The class loader used by this system */
  val classLoader: ClassLoader
  
  /** Configuration root path */
  val ConfigPath: String = "akka"
  
  /** The log level for this system */
  val LogLevel: String
  
  /** Whether to log configuration on start */
  val LogConfigOnStart: Boolean
  
  /** Home directory for the actor system */
  val Home: Option[String]
  
  /** The provider class for actor references */
  val ProviderClass: String
  
  /** Supervisor strategy for guardian actors */
  val SupervisorStrategyClass: String
  
  /** Creation timeout for actors */
  val CreationTimeout: Timeout
  
  /** Ask timeout for actor asks */
  val AskTimeout: Timeout
}

Extended Actor System

Extended functionality for internal system operations and advanced use cases.

/**
 * Extended actor system providing additional internal functionality
 */
abstract class ExtendedActorSystem extends ActorSystem {
  /** The provider for actor references in this system */
  def provider: ActorRefProvider
  
  /** The guardian actor responsible for user actors */
  def guardian: InternalActorRef
  
  /** The system guardian actor */
  def systemGuardian: InternalActorRef
  
  /** The dead letters actor */
  def deadLetters: ActorRef
  
  /** Dynamic access for reflective operations */
  def dynamicAccess: DynamicAccess
  
  /** Thread factory for creating threads */
  def threadFactory: ThreadFactory
  
  /** Create a UID for actors */
  def uid: Int
  
  /** Looks up an extension by its ID */
  def extension[T <: Extension](ext: ExtensionId[T]): T
  
  /** Checks if an extension is registered */
  def hasExtension(ext: ExtensionId[_ <: Extension]): Boolean
}

Bootstrap Setup

Configuration and setup options for actor system initialization.

/**
 * Bootstrap setup for actor system creation
 */
final class BootstrapSetup private (
  val config: Option[Config],
  val classLoader: Option[ClassLoader],
  val defaultExecutionContext: Option[ExecutionContext]
) extends Setup

object BootstrapSetup {
  /** Create bootstrap setup with default values */
  def apply(): BootstrapSetup
  
  /** Create bootstrap setup with specified config */
  def apply(config: Config): BootstrapSetup
  
  /** Create bootstrap setup with config and classloader */
  def apply(config: Config, classLoader: ClassLoader): BootstrapSetup
  
  /** Create bootstrap setup with all options */
  def apply(
    config: Config,
    classLoader: ClassLoader, 
    defaultExecutionContext: ExecutionContext
  ): BootstrapSetup
}

/**
 * Actor system setup combining multiple setup instances
 */
final class ActorSystemSetup private (private val setups: immutable.Seq[Setup]) {
  /** Get setup of specific type */
  def get[T <: Setup: ClassTag]: Option[T]
  
  /** Add or replace setup */
  def withSetup[T <: Setup](setup: T): ActorSystemSetup
}

object ActorSystemSetup {
  /** Create empty actor system setup */  
  def apply(): ActorSystemSetup
  
  /** Create setup with initial setup instances */
  def apply(setups: Setup*): ActorSystemSetup
}

Provider Selection

Selection of actor reference providers for different deployment scenarios.

/**
 * Actor reference provider selection
 */
abstract class ProviderSelection extends Setup

object ProviderSelection {
  /** Local provider for single-JVM deployments */
  case object Local extends ProviderSelection
  
  /** Remote provider for distributed deployments */  
  case object Remote extends ProviderSelection
  
  /** Cluster provider for clustered deployments */
  case object Cluster extends ProviderSelection
  
  /** Custom provider with specified class name */
  final case class Custom(fqcn: String) extends ProviderSelection
}

System Termination

Graceful shutdown and termination management.

/**
 * Represents a terminated actor system
 */
final case class Terminated(ref: ActorRef) extends AutoReceivedMessage

/**
 * Coordinated shutdown management for graceful system termination
 */
class CoordinatedShutdown(system: ExtendedActorSystem) extends Extension {
  /** Run shutdown process */
  def run(reason: CoordinatedShutdown.Reason): Future[Done]
  
  /** Add task to shutdown phase */
  def addTask(phase: String, taskName: String)(task: () => Future[Done]): Unit
  
  /** Get shutdown reason if shutdown is in progress */
  def shutdownReason(): Option[CoordinatedShutdown.Reason]
}

object CoordinatedShutdown extends ExtensionId[CoordinatedShutdown] {
  /** Shutdown reasons */
  abstract class Reason(val name: String)
  
  case object ActorSystemTerminateReason extends Reason("actor-system-terminate")
  case object JvmExitReason extends Reason("jvm-exit")
  case object CLusterLeavingReason extends Reason("cluster-leaving")
  case object CLusterDowningReason extends Reason("cluster-downing")
  
  /** Shutdown phases */
  val PhaseBeforeServiceUnbind = "before-service-unbind"
  val PhaseServiceUnbind = "service-unbind"
  val PhaseServiceRequestsDone = "service-requests-done"
  val PhaseServiceStop = "service-stop"
  val PhaseBeforeClusterShutdown = "before-cluster-shutdown"
  val PhaseClusterShutdown = "cluster-shutdown"
  val PhaseBeforeActorSystemTerminate = "before-actor-system-terminate"
  val PhaseActorSystemTerminate = "actor-system-terminate"
}

Usage Examples:

import akka.actor.{ActorSystem, CoordinatedShutdown}
import scala.concurrent.duration._

val system = ActorSystem("MySystem")
val coordShutdown = CoordinatedShutdown(system)

// Add custom shutdown task
coordShutdown.addTask(CoordinatedShutdown.PhaseServiceStop, "cleanup-resources") { () =>
  // Cleanup logic here
  Future.successful(Done)
}

// Shutdown the system
coordShutdown.run(CoordinatedShutdown.ActorSystemTerminateReason)

Install with Tessl CLI

npx tessl i tessl/maven-com-typesafe-akka--akka-actor-2-13

docs

actor-behavior.md

actor-lifecycle.md

actor-system.md

events-logging.md

index.md

io.md

messaging.md

routing.md

supervision.md

utilities.md

tile.json