Package com.scivicslab.pojoactor.core
Class ActorSystem
java.lang.Object
com.scivicslab.pojoactor.core.ActorSystem
- Direct Known Subclasses:
IIActorSystem
A lightweight actor system implementation that manages actor lifecycles and thread pools.
This system provides a framework for creating and managing actors with concurrent message processing.
- Since:
- 1.0.0
- Author:
- devteam@scivics-lab.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for creating ActorSystem instances with custom configurations. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConcurrentHashMap<String, ActorRef<?>> A name to an ActorRef correspondance.protected Stringprotected List<WorkerPool> -
Constructor Summary
ConstructorsConstructorDescriptionActorSystem(String systemName) Constructs an ActorSystem with the specified name and default thread pool.ActorSystem(String systemName, int threadNum) Constructs an ActorSystem with the specified name and thread count. -
Method Summary
Modifier and TypeMethodDescription<T> ActorRef<T> Creates a new actor with the specified name and object.<T> ActorRef<T> Add the directly generated Actor to the ActorSystem.<T> ActorRef<T> Add the directly generated Actor to the ActorSystem while changing the name used within the ActorSystem.<T> ActorRef<T> Deprecated.booleanaddWorkStealingPool(int threadNum) Adds a new work stealing pool to the actor system.<T> ActorRef<T> Retrieves an actor by name.Gets the current logger instance.Returns the default work stealing pool of the actor system.getWorkStealingPool(int n) Returns a work stealing pool at the specified index.booleanChecks if an actor with the specified name exists in the system.voidinitLogger(String loggerName) Initializes the system logger with the specified name.booleanisAlive()Checks if the actor system is alive (no thread pools are shut down).booleanChecks if a specific actor is alive.Returns a list of all actor names in the system.voidremoveActor(String actorName) Removes an actor from the system.root()Deprecated.UsegetActor(String)with "ROOT" insteadvoidSets the logger for the actor system.voidTerminates the actor system by closing all actors and shutting down thread pools.toString()Returns a string representation of the actor system.
-
Field Details
-
systemName
-
actors
A name to an ActorRef correspondance. -
workerPools
-
-
Constructor Details
-
ActorSystem
Constructs an ActorSystem with the specified name and default thread pool.- Parameters:
systemName- the name of the actor system
-
ActorSystem
Constructs an ActorSystem with the specified name and thread count.- Parameters:
systemName- the name of the actor systemthreadNum- the number of threads in the worker pool
-
-
Method Details
-
terminate
public void terminate()Terminates the actor system by closing all actors and shutting down thread pools. Waits up to 60 seconds for graceful termination. -
actorOf
Creates a new actor with the specified name and object.- Type Parameters:
T- the type of the actor object- Parameters:
actorName- the unique name for the actorobject- the object that will handle messages for this actor- Returns:
- a reference to the created actor
-
addActor
Deprecated.UseaddActor(ActorRef)insteadAdds an existing actor to the system with the specified name.- Type Parameters:
T- the type of the actor object- Parameters:
actorName- the name to associate with the actoractor- the actor reference to add- Returns:
- the added actor reference
-
addActor
Add the directly generated Actor to the ActorSystem.- Parameters:
actor- An ActorRef object to be added to the ActorSystem.- Returns:
- The same ActorRef object as the argument.
-
addActor
Add the directly generated Actor to the ActorSystem while changing the name used within the ActorSystem.- Parameters:
actor- An ActorRef object to be added to the ActorSystem.actorName- A name to be associated with the ActorRef object.- Returns:
- The same ActorRef object as the argument.
-
addWorkStealingPool
public boolean addWorkStealingPool(int threadNum) Adds a new work stealing pool to the actor system.- Parameters:
threadNum- the number of threads in the new pool- Returns:
- true if the pool was successfully added
-
hasActor
Checks if an actor with the specified name exists in the system.- Parameters:
actorName- the name of the actor to check- Returns:
- true if the actor exists, false otherwise
-
initLogger
Initializes the system logger with the specified name.- Parameters:
loggerName- the name for the logger
-
isAlive
public boolean isAlive()Checks if the actor system is alive (no thread pools are shut down).- Returns:
- true if the system is alive, false otherwise
-
isAlive
Checks if a specific actor is alive.- Parameters:
actorName- the name of the actor to check- Returns:
- true if the actor exists and is alive, false otherwise
-
listActorNames
Returns a list of all actor names in the system.- Returns:
- a list containing the names of all actors
-
removeActor
Removes an actor from the system.- Parameters:
actorName- the name of the actor to remove
-
root
Deprecated.UsegetActor(String)with "ROOT" insteadReturns the root actor of the system.- Returns:
- the root actor reference
-
toString
Returns a string representation of the actor system. -
setLogger
Sets the logger for the actor system.- Parameters:
logger- the logger instance to use
-
getLogger
Gets the current logger instance.- Returns:
- the current logger
-
getActor
Retrieves an actor by name.- Type Parameters:
T- the type of the actor object- Parameters:
actorName- the name of the actor to retrieve- Returns:
- the actor reference, or null if not found
-
getWorkStealingPool
Returns the default work stealing pool of the actor system.- Returns:
- the default work stealing pool (index 0)
-
getWorkStealingPool
Returns a work stealing pool at the specified index.- Parameters:
n- the index of the work stealing pool to return- Returns:
- the work stealing pool at the specified index
-
addActor(ActorRef)instead