Class DistributedActorSystem
java.lang.Object
com.scivicslab.pojoactor.core.ActorSystem
com.scivicslab.pojoactor.workflow.IIActorSystem
com.scivicslab.pojoactor.workflow.distributed.DistributedActorSystem
Distributed actor system with HTTP-based inter-node communication.
This class extends IIActorSystem to provide distributed actor
capabilities. Each instance runs an embedded HTTP server that accepts
actor invocation requests from remote nodes.
Architecture
Node 1 (host1:8081) Node 2 (host2:8082)
┌────────────────────────┐ ┌────────────────────────┐
│ DistributedActorSystem │ │ DistributedActorSystem │
│ ┌────────────────────┐ │ │ ┌────────────────────┐ │
│ │ HttpServer :8081 │ │ │ │ HttpServer :8082 │ │
│ └────────────────────┘ │ │ └────────────────────┘ │
│ Local Actors: │◄────────│ HTTP POST │
│ - math │ │ Local Actors: │
│ - calculator │ │ - logger │
└────────────────────────┘ └────────────────────────┘
Usage Example
Node 1 Program (ServerNode.java) - Deploy to host1:8081
public class ServerNode {
public static void main(String[] args) throws IOException {
// Create distributed actor system on this node
DistributedActorSystem system =
new DistributedActorSystem("node1", "0.0.0.0", 8081);
// Register math actor on this node
MathPlugin math = new MathPlugin();
MathIIAR mathActor = new MathIIAR("math", math, system);
system.addIIActor(mathActor);
System.out.println("Server node ready on port 8081");
// Keep running to accept requests
Thread.currentThread().join();
}
}
Node 2 Program (ClientNode.java) - Deploy to host2:8082
public class ClientNode {
public static void main(String[] args) throws IOException {
// Create distributed actor system on this node
DistributedActorSystem system =
new DistributedActorSystem("node2", "0.0.0.0", 8082);
// Register remote node1 (must know its address)
system.registerRemoteNode("node1", "host1.example.com", 8081);
// Get remote actor reference
RemoteActorRef remoteMath = system.getRemoteActor("node1", "math");
// Call remote actor
ActionResult result = remoteMath.callByActionName("add", "5,3");
System.out.println("Result: " + result.getResult());
}
}
- Since:
- 2.5.0, 2.5.0
- Author:
- devteam@scivics-lab.com
-
Nested Class Summary
Nested classes/interfaces inherited from class com.scivicslab.pojoactor.core.ActorSystem
ActorSystem.Builder -
Field Summary
Fields inherited from class com.scivicslab.pojoactor.core.ActorSystem
actors, systemName, workerPools -
Constructor Summary
ConstructorsConstructorDescriptionDistributedActorSystem(String nodeId, int port) Constructs a new DistributedActorSystem listening on all interfaces.DistributedActorSystem(String nodeId, String host, int port) Constructs a new DistributedActorSystem. -
Method Summary
Modifier and TypeMethodDescriptiongetHost()Returns the hostname for this system.Returns the node identifier for this system.intgetPort()Returns the HTTP port for this system.getRemoteActor(String nodeId, String actorName) Gets a remote actor reference.voidregisterRemoteNode(String nodeId, String host, int port) Registers a remote node in the node registry.voidTerminates this actor system and stops the HTTP server.Methods inherited from class com.scivicslab.pojoactor.workflow.IIActorSystem
addIIActor, getIIActor, getIIActorCount, hasIIActor, listActorNames, removeIIActor, resolveActorPath, terminateIIActorsMethods inherited from class com.scivicslab.pojoactor.core.ActorSystem
actorOf, addActor, addActor, addActor, addWorkStealingPool, getActor, getLogger, getWorkStealingPool, getWorkStealingPool, hasActor, initLogger, isAlive, isAlive, removeActor, root, setLogger, toString
-
Constructor Details
-
DistributedActorSystem
Constructs a new DistributedActorSystem.- Parameters:
nodeId- unique identifier for this nodehost- hostname or IP address for this nodeport- HTTP port number to listen on- Throws:
IOException- if HTTP server cannot be created
-
DistributedActorSystem
Constructs a new DistributedActorSystem listening on all interfaces.- Parameters:
nodeId- unique identifier for this nodeport- HTTP port number to listen on- Throws:
IOException- if HTTP server cannot be created
-
-
Method Details
-
registerRemoteNode
Registers a remote node in the node registry.- Parameters:
nodeId- the remote node's identifierhost- the remote node's hostname or IPport- the remote node's HTTP port
-
getRemoteActor
Gets a remote actor reference.- Parameters:
nodeId- the node hosting the actoractorName- the name of the actor- Returns:
- a RemoteActorRef for the specified actor
- Throws:
IllegalArgumentException- if the node is not registered
-
getNodeId
Returns the node identifier for this system.- Returns:
- the node ID
-
getHost
Returns the hostname for this system.- Returns:
- the host
-
getPort
public int getPort()Returns the HTTP port for this system.- Returns:
- the port
-
terminate
public void terminate()Terminates this actor system and stops the HTTP server.- Overrides:
terminatein classActorSystem
-