Class DistributedActorSystem
java.lang.Object
com.scivicslab.pojoactor.core.distributed.DistributedActorSystem
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidclose()Returns the underlying local actor system.Returns this node's identity.getNodes()Returns all nodes in the cluster (including this node).remoteActorOf(NodeInfo node, String actorName) Returns aRemoteActorReffor an actor on the given remote node.voidstartHttpServer(int port) Starts anHttpActorServerto receive messages via HTTP.voidstartServer(String brokers) Starts aKafkaActorServerto receive messages from Kafka.
-
Method Details
-
startServer
Starts aKafkaActorServerto receive messages from Kafka. Only needed when usingKafkaTransport.- Parameters:
brokers- Kafka bootstrap servers
-
startHttpServer
Starts anHttpActorServerto receive messages via HTTP. Suited for HPC clusters (Slurm, Grid Engine) usingHttpTransport.- Parameters:
port- the port to listen on (should matchmyNode.getPort())- Throws:
IOException- if the port cannot be bound
-
remoteActorOf
Returns aRemoteActorReffor an actor on the given remote node.- Parameters:
node- the remote nodeactorName- the name of the remote actor- Returns:
- a proxy that delegates calls via the configured transport
-
getNodes
Returns all nodes in the cluster (including this node). -
getMyNode
Returns this node's identity. -
getLocalActorSystem
Returns the underlying local actor system. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
builder
-