Class DistributedActorSystem

java.lang.Object
com.scivicslab.pojoactor.core.ActorSystem
com.scivicslab.pojoactor.workflow.IIActorSystem
com.scivicslab.pojoactor.workflow.distributed.DistributedActorSystem

public class DistributedActorSystem extends IIActorSystem
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
  • Constructor Details

    • DistributedActorSystem

      public DistributedActorSystem(String nodeId, String host, int port) throws IOException
      Constructs a new DistributedActorSystem.
      Parameters:
      nodeId - unique identifier for this node
      host - hostname or IP address for this node
      port - HTTP port number to listen on
      Throws:
      IOException - if HTTP server cannot be created
    • DistributedActorSystem

      public DistributedActorSystem(String nodeId, int port) throws IOException
      Constructs a new DistributedActorSystem listening on all interfaces.
      Parameters:
      nodeId - unique identifier for this node
      port - HTTP port number to listen on
      Throws:
      IOException - if HTTP server cannot be created
  • Method Details

    • registerRemoteNode

      public void registerRemoteNode(String nodeId, String host, int port)
      Registers a remote node in the node registry.
      Parameters:
      nodeId - the remote node's identifier
      host - the remote node's hostname or IP
      port - the remote node's HTTP port
    • getRemoteActor

      public RemoteActorRef getRemoteActor(String nodeId, String actorName)
      Gets a remote actor reference.
      Parameters:
      nodeId - the node hosting the actor
      actorName - the name of the actor
      Returns:
      a RemoteActorRef for the specified actor
      Throws:
      IllegalArgumentException - if the node is not registered
    • getNodeId

      public String getNodeId()
      Returns the node identifier for this system.
      Returns:
      the node ID
    • getHost

      public String 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:
      terminate in class ActorSystem