Class NodeDiscoveryFactory
java.lang.Object
com.scivicslab.pojoactor.core.distributed.discovery.NodeDiscoveryFactory
Factory for automatic node discovery based on runtime environment.
This factory detects the execution environment (Slurm, Kubernetes,
Grid Engine) and returns an appropriate NodeDiscovery implementation.
Supported Environments
- Slurm - Detects SLURM_JOB_NODELIST environment variable
- Kubernetes - Detects POD_NAME and KUBERNETES_SERVICE_HOST
- Grid Engine - Detects PE_HOSTFILE environment variable
Usage Example
public static void main(String[] args) throws IOException {
// Auto-detect environment and discover nodes
NodeDiscovery discovery = NodeDiscoveryFactory.autoDetect();
// Create distributed actor system
DistributedActorSystem system = new DistributedActorSystem(
discovery.getMyNodeId(),
discovery.getMyHost(),
discovery.getMyPort()
);
// Register all remote nodes
for (NodeInfo node : discovery.getAllNodes()) {
if (!node.getNodeId().equals(discovery.getMyNodeId())) {
system.registerRemoteNode(
node.getNodeId(),
node.getHost(),
node.getPort()
);
}
}
// Register actors and start processing
// ...
}
Helper Method
For even simpler usage, use createDistributedSystem(int):
public static void main(String[] args) throws IOException {
// Auto-detect environment and create system with all nodes registered
DistributedActorSystem system = NodeDiscoveryFactory.createDistributedSystem(8080);
// All remote nodes are already registered - just add actors
// ...
}
- Since:
- 2.5.0
- Author:
- devteam@scivics-lab.com
-
Method Summary
Modifier and TypeMethodDescriptionstatic NodeDiscoveryAutomatically detects the execution environment and returns an appropriate NodeDiscovery implementation.static NodeDiscoveryautoDetect(int port) Automatically detects the execution environment and returns an appropriate NodeDiscovery implementation with specified port.static DistributedActorSystemCreates a DistributedActorSystem with default port 8080.static DistributedActorSystemcreateDistributedSystem(int port) Creates a DistributedActorSystem with automatic node discovery and registration.
-
Method Details
-
autoDetect
Automatically detects the execution environment and returns an appropriate NodeDiscovery implementation.Detection priority:
- Slurm (checks SLURM_JOB_NODELIST)
- Kubernetes (checks POD_NAME and KUBERNETES_SERVICE_HOST)
- Grid Engine (checks PE_HOSTFILE)
- Returns:
- a NodeDiscovery implementation for the detected environment
- Throws:
IllegalStateException- if no supported environment is detected
-
autoDetect
Automatically detects the execution environment and returns an appropriate NodeDiscovery implementation with specified port.- Parameters:
port- the default port for actor communication- Returns:
- a NodeDiscovery implementation for the detected environment
- Throws:
IllegalStateException- if no supported environment is detected
-
createDistributedSystem
Creates a DistributedActorSystem with automatic node discovery and registration.This convenience method:
- Auto-detects the environment
- Creates a DistributedActorSystem
- Registers all remote nodes automatically
- Parameters:
port- the port for actor communication- Returns:
- a fully configured DistributedActorSystem
- Throws:
IOException- if the HTTP server cannot be created
-
createDistributedSystem
Creates a DistributedActorSystem with default port 8080.- Returns:
- a fully configured DistributedActorSystem
- Throws:
IOException- if the HTTP server cannot be created
-