Class DistributedActorSystem

java.lang.Object
com.scivicslab.pojoactor.core.distributed.DistributedActorSystem
All Implemented Interfaces:
AutoCloseable

public class DistributedActorSystem extends Object implements AutoCloseable
Extends a local ActorSystem with distributed capabilities.

Combines a TransportLayer (HTTP or Kafka) with a NodeDiscovery strategy to enable actors to communicate across nodes with the same API as local actors.

K8s / Kafka Example


 NodeDiscovery discovery = NodeDiscoveryFactory.autoDetect();
 KafkaTransport transport = new KafkaTransport(
     new NodeInfo(discovery.getMyNodeId(), discovery.getMyHost(), discovery.getMyPort()),
     "kafka:9092"
 );

 DistributedActorSystem system = DistributedActorSystem.builder()
     .localActorSystem(new ActorSystem("my-app"))
     .transport(transport)
     .discovery(discovery)
     .build();

 system.startServer("kafka:9092"); // start receiving messages

 // Get a reference to a remote actor
 RemoteActorRef remote = system.remoteActorOf(system.getNodes().get(1), "order-saga");
 ActionResult result = remote.callByActionName("start", orderJson);
 

Slurm / HTTP Example


 DistributedActorSystem system = DistributedActorSystem.builder()
     .localActorSystem(new ActorSystem("slurm-worker"))
     .transport(new HttpTransport())
     .discovery(NodeDiscoveryFactory.autoDetect())
     .build();
 
Since:
3.1.0
  • Method Details

    • startServer

      public void startServer(String brokers)
      Starts a KafkaActorServer to receive messages from Kafka. Only needed when using KafkaTransport.
      Parameters:
      brokers - Kafka bootstrap servers
    • startHttpServer

      public void startHttpServer(int port) throws IOException
      Starts an HttpActorServer to receive messages via HTTP. Suited for HPC clusters (Slurm, Grid Engine) using HttpTransport.
      Parameters:
      port - the port to listen on (should match myNode.getPort())
      Throws:
      IOException - if the port cannot be bound
    • remoteActorOf

      public RemoteActorRef remoteActorOf(NodeInfo node, String actorName)
      Returns a RemoteActorRef for an actor on the given remote node.
      Parameters:
      node - the remote node
      actorName - the name of the remote actor
      Returns:
      a proxy that delegates calls via the configured transport
    • getNodes

      public List<NodeInfo> getNodes()
      Returns all nodes in the cluster (including this node).
    • getMyNode

      public NodeInfo getMyNode()
      Returns this node's identity.
    • getLocalActorSystem

      public ActorSystem getLocalActorSystem()
      Returns the underlying local actor system.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • builder

      public static DistributedActorSystem.Builder builder()