Class ActorSystem
- All Implemented Interfaces:
ActorRefFactory
,ClassicActorSystemProvider
- Direct Known Subclasses:
ExtendedActorSystem
There are several possibilities for creating actors (see pekko.actor.Props
for details on props
):
// Java or Scala
system.actorOf(props, "name")
system.actorOf(props)
// Scala
system.actorOf(Props[MyActor], "name")
system.actorOf(Props(classOf[MyActor], arg1, arg2), "name")
// Java
system.actorOf(Props.create(MyActor.class), "name");
system.actorOf(Props.create(MyActor.class, arg1, arg2), "name");
Where no name is given explicitly, one will be automatically generated.
Important Notice:
This class is not meant to be extended by user code. If you want to
actually roll your own Pekko, it will probably be better to look into
extending pekko.actor.ExtendedActorSystem
instead, but beware that you
are completely on your own in that case!
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Settings are the overall ActorSystem Settings which also provides a convenient access to the Config object.static class
INTERNAL API -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ActorPath
Construct a path below the application guardian to be used withActorRefFactory.actorSelection(java.lang.String)
.abstract ActorPath
Construct a path below the application guardian to be used withActorRefFactory.actorSelection(java.lang.String)
.static ActorSystem
apply()
Creates a new ActorSystem with the name "default", obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class.static ActorSystem
Creates a new ActorSystem with the specified name, obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class.static ActorSystem
Creates a new ActorSystem with the specified name, and the specified Config, then obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class.static ActorSystem
apply
(String name, com.typesafe.config.Config config, ClassLoader classLoader) Creates a new ActorSystem with the specified name, the specified Config, and specified ClassLoaderstatic ActorSystem
apply
(String name, BootstrapSetup bootstrapSetup) Scala API: Shortcut for creating an actor system with custom bootstrap settings.static ActorSystem
apply
(String name, ActorSystemSetup setup) Scala API: Creates a new actor system with the specified name and settings The core actor system settings are defined inBootstrapSetup
static ActorSystem
apply
(String name, scala.Option<com.typesafe.config.Config> config, scala.Option<ClassLoader> classLoader, scala.Option<scala.concurrent.ExecutionContext> defaultExecutionContext) Creates a new ActorSystem with the specified name, the specified ClassLoader if given, otherwise obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class.static scala.Option<com.typesafe.config.Config>
static scala.Option<ClassLoader>
static scala.Option<scala.concurrent.ExecutionContext>
Java API: Create a new child actor path.static ActorSystem
create()
Creates a new ActorSystem with the name "default", obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class.static ActorSystem
Creates a new ActorSystem with the specified name, obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class.static ActorSystem
Creates a new ActorSystem with the specified name, and the specified Config, then obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class.static ActorSystem
create
(String name, com.typesafe.config.Config config, ClassLoader classLoader) Creates a new ActorSystem with the specified name, the specified Config, and specified ClassLoaderstatic ActorSystem
create
(String name, com.typesafe.config.Config config, ClassLoader classLoader, scala.concurrent.ExecutionContext defaultExecutionContext) Creates a new ActorSystem with the specified name, the specified Config, the specified ClassLoader, and the specified ExecutionContext.static ActorSystem
create
(String name, BootstrapSetup bootstrapSetup) Java API: Shortcut for creating an actor system with custom bootstrap settings.static ActorSystem
create
(String name, ActorSystemSetup setups) Java API: Creates a new actor system with the specified name and settings The core actor system settings are defined inBootstrapSetup
abstract ActorRef
Actor reference where messages are re-routed to which were addressed to stopped or non-existing actors.descendant
(Iterable<String> names) Java API: Recursively create a descendant’s path by appending all child names.abstract scala.concurrent.ExecutionContextExecutor
Default dispatcher as configured.abstract Dispatchers
Helper object for looking up configured dispatchers.abstract EventStream
Main event bus of this actor system, used for example for logging.abstract <T extends Extension>
Textension
(ExtensionId<T> ext) Returns the payload that is associated with the provided extension throws an IllegalStateException if it is not registered.scala.concurrent.ExecutionContextExecutor
Java API: Default dispatcher as configured.Java API: Main event bus of this actor system, used for example for logging.Java API: Light-weight scheduler for running asynchronous tasks after some deadline in the future.abstract CompletionStage<Terminated>
Returns a CompletionStage which will be completed after the ActorSystem has been terminated and termination hooks have been executed.abstract boolean
hasExtension
(ExtensionId<? extends Extension> ext) Returns whether the specified extension is already registered, this method can potentially block, waiting for the initialization of the payload, if is in the process of registration from another Thread of executionabstract LoggingAdapter
log()
Convenient logging adapter for logging to theeventStream()
.abstract void
Log the configuration.abstract org.apache.pekko.dispatch.Mailboxes
Helper object for looking up configured mailbox types.abstract String
name()
The name of this actor system, used to distinguish multiple ones within the same JVM & class loader.abstract <T extends Extension>
TregisterExtension
(ExtensionId<T> ext) Registers the provided extension and creates its payload, if this extension isn't already registered This method has putIfAbsent-semantics, this method can potentially block, waiting for the initialization of the payload, if is in the process of registration from another Thread of executionabstract void
Java API: Register a block of code (callback) to run afterActorSystem.terminate
has been issued and all actors in this actor system have been stopped.abstract <T> void
registerOnTermination
(scala.Function0<T> code) Register a block of code (callback) to run afterActorSystem.terminate
has been issued and all actors in this actor system have been stopped.abstract Scheduler
Light-weight scheduler for running asynchronous tasks after some deadline in the future.abstract ActorSystem.Settings
settings()
The core settings extracted from the supplied configuration.long
Start-up time in milliseconds since the epoch.abstract scala.concurrent.Future<Terminated>
Terminates this actor system by runningCoordinatedShutdown
with reasonCoordinatedShutdown.ActorSystemTerminateReason
.long
uptime()
Up-time of this actor system in seconds.static String
Version()
abstract scala.concurrent.Future<Terminated>
Returns a Future which will be completed after the ActorSystem has been terminated and termination hooks have been executed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.pekko.actor.ActorRefFactory
actorOf, actorOf, actorSelection, actorSelection, guardian, lookupRoot, provider, stop, systemImpl
Methods inherited from interface org.apache.pekko.actor.ClassicActorSystemProvider
classicSystem
-
Constructor Details
-
ActorSystem
public ActorSystem()
-
-
Method Details
-
Version
-
create
Creates a new ActorSystem with the name "default", obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class. Then it loads the default reference configuration using the ClassLoader. -
create
Creates a new ActorSystem with the specified name, obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class. Then it loads the default reference configuration using the ClassLoader. -
create
Java API: Creates a new actor system with the specified name and settings The core actor system settings are defined inBootstrapSetup
-
create
Java API: Shortcut for creating an actor system with custom bootstrap settings. Same behavior as callingActorSystem.create(name, ActorSystemSetup.create(bootstrapSettings))
-
create
Creates a new ActorSystem with the specified name, and the specified Config, then obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class. -
create
public static ActorSystem create(String name, com.typesafe.config.Config config, ClassLoader classLoader) Creates a new ActorSystem with the specified name, the specified Config, and specified ClassLoader -
create
public static ActorSystem create(String name, com.typesafe.config.Config config, ClassLoader classLoader, scala.concurrent.ExecutionContext defaultExecutionContext) Creates a new ActorSystem with the specified name, the specified Config, the specified ClassLoader, and the specified ExecutionContext. The ExecutionContext will be used as the default executor inside this ActorSystem. Ifnull
is passed in for the Config, ClassLoader and/or ExecutionContext parameters, the respective default value will be used. If no Config is given, the default reference config will be obtained from the ClassLoader. If no ClassLoader is given, it obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class. If no ExecutionContext is given, the system will fallback to the executor configured under "pekko.actor.default-dispatcher.default-executor.fallback". Note that the given ExecutionContext will be used by all dispatchers that have been configured with executor = "default-executor", including those that have not defined the executor setting and thereby fallback to the default of "default-dispatcher.executor". -
apply
Creates a new ActorSystem with the name "default", obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class. Then it loads the default reference configuration using the ClassLoader. -
apply
Creates a new ActorSystem with the specified name, obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class. Then it loads the default reference configuration using the ClassLoader. -
apply
Scala API: Creates a new actor system with the specified name and settings The core actor system settings are defined inBootstrapSetup
-
apply
Scala API: Shortcut for creating an actor system with custom bootstrap settings. Same behavior as callingActorSystem(name, ActorSystemSetup(bootstrapSetup))
-
apply
Creates a new ActorSystem with the specified name, and the specified Config, then obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class. -
apply
public static ActorSystem apply(String name, com.typesafe.config.Config config, ClassLoader classLoader) Creates a new ActorSystem with the specified name, the specified Config, and specified ClassLoader -
apply
public static ActorSystem apply(String name, scala.Option<com.typesafe.config.Config> config, scala.Option<ClassLoader> classLoader, scala.Option<scala.concurrent.ExecutionContext> defaultExecutionContext) Creates a new ActorSystem with the specified name, the specified ClassLoader if given, otherwise obtains the current ClassLoader by first inspecting the current threads' getContextClassLoader, then tries to walk the stack to find the callers class loader, then falls back to the ClassLoader associated with the ActorSystem class. If an ExecutionContext is given, it will be used as the default executor inside this ActorSystem. If no ExecutionContext is given, the system will fallback to the executor configured under "pekko.actor.default-dispatcher.default-executor.fallback". The system will use the passed in config, or falls back to the default reference configuration using the ClassLoader. -
apply$default$2
public static scala.Option<com.typesafe.config.Config> apply$default$2() -
apply$default$3
-
apply$default$4
public static scala.Option<scala.concurrent.ExecutionContext> apply$default$4() -
name
The name of this actor system, used to distinguish multiple ones within the same JVM & class loader. -
settings
The core settings extracted from the supplied configuration. -
logConfiguration
public abstract void logConfiguration()Log the configuration. -
$div
Construct a path below the application guardian to be used withActorRefFactory.actorSelection(java.lang.String)
. -
child
Java API: Create a new child actor path. -
$div
Construct a path below the application guardian to be used withActorRefFactory.actorSelection(java.lang.String)
. -
descendant
Java API: Recursively create a descendant’s path by appending all child names. -
startTime
public long startTime()Start-up time in milliseconds since the epoch. -
uptime
public long uptime()Up-time of this actor system in seconds. -
eventStream
Main event bus of this actor system, used for example for logging. -
getEventStream
Java API: Main event bus of this actor system, used for example for logging. -
log
Convenient logging adapter for logging to theeventStream()
. -
deadLetters
Actor reference where messages are re-routed to which were addressed to stopped or non-existing actors. Delivery to this actor is done on a best effort basis and hence not strictly guaranteed. -
scheduler
Light-weight scheduler for running asynchronous tasks after some deadline in the future. Not terribly precise but cheap. -
getScheduler
Java API: Light-weight scheduler for running asynchronous tasks after some deadline in the future. Not terribly precise but cheap. -
dispatchers
Helper object for looking up configured dispatchers. -
dispatcher
public abstract scala.concurrent.ExecutionContextExecutor dispatcher()Default dispatcher as configured. This dispatcher is used for all actors in the actor system which do not have a different dispatcher configured explicitly. Importing this member will place the default MessageDispatcher in scope.- Specified by:
dispatcher
in interfaceActorRefFactory
-
getDispatcher
public scala.concurrent.ExecutionContextExecutor getDispatcher()Java API: Default dispatcher as configured. This dispatcher is used for all actors in the actor system which do not have a different dispatcher configured explicitly. Importing this member will place the default MessageDispatcher in scope. -
mailboxes
public abstract org.apache.pekko.dispatch.Mailboxes mailboxes()Helper object for looking up configured mailbox types. -
registerOnTermination
public abstract <T> void registerOnTermination(scala.Function0<T> code) Register a block of code (callback) to run afterActorSystem.terminate
has been issued and all actors in this actor system have been stopped. Multiple code blocks may be registered by calling this method multiple times. The callbacks will be run sequentially in reverse order of registration, i.e. last registration is run first. Note that ActorSystem will not terminate until all the registered callbacks are finished.Throws a RejectedExecutionException if the System has already been terminated or if termination has been initiated.
Scala API
-
registerOnTermination
Java API: Register a block of code (callback) to run afterActorSystem.terminate
has been issued and all actors in this actor system have been stopped. Multiple code blocks may be registered by calling this method multiple times. The callbacks will be run sequentially in reverse order of registration, i.e. last registration is run first. Note that ActorSystem will not terminate until all the registered callbacks are finished.Throws a RejectedExecutionException if the System has already been terminated or if termination has been initiated.
-
terminate
Terminates this actor system by runningCoordinatedShutdown
with reasonCoordinatedShutdown.ActorSystemTerminateReason
.If
pekko.coordinated-shutdown.run-by-actor-system-terminate
is configured tooff
it will not runCoordinatedShutdown
, but theActorSystem
and its actors will still be terminated.This will stop the guardian actor, which in turn will recursively stop all its child actors, and finally the system guardian (below which the logging actors reside) and then execute all registered termination handlers (see
registerOnTermination(scala.Function0<T>)
). Be careful to not schedule any operations on completion of the returned future using the dispatcher of this actor system as it will have been shut down before the future completes. -
whenTerminated
Returns a Future which will be completed after the ActorSystem has been terminated and termination hooks have been executed. If you registered any callback withregisterOnTermination(scala.Function0<T>)
, the returned Future from this method will not complete until all the registered callbacks are finished. Be careful to not schedule any operations, such asonComplete
, on the dispatchers (ExecutionContext
) of this actor system as they will have been shut down before this future completes. -
getWhenTerminated
Returns a CompletionStage which will be completed after the ActorSystem has been terminated and termination hooks have been executed. If you registered any callback withregisterOnTermination(scala.Function0<T>)
, the returned CompletionStage from this method will not complete until all the registered callbacks are finished. Be careful to not schedule any operations, such asthenRunAsync
, on the dispatchers (Executor
) of this actor system as they will have been shut down before this CompletionStage completes. -
registerExtension
Registers the provided extension and creates its payload, if this extension isn't already registered This method has putIfAbsent-semantics, this method can potentially block, waiting for the initialization of the payload, if is in the process of registration from another Thread of execution -
extension
Returns the payload that is associated with the provided extension throws an IllegalStateException if it is not registered. This method can potentially block, waiting for the initialization of the payload, if is in the process of registration from another Thread of execution -
hasExtension
Returns whether the specified extension is already registered, this method can potentially block, waiting for the initialization of the payload, if is in the process of registration from another Thread of execution
-