Class NodeDiscoveryFactory

java.lang.Object
com.scivicslab.pojoactor.core.distributed.discovery.NodeDiscoveryFactory

public class NodeDiscoveryFactory extends Object
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 Details

    • autoDetect

      public static NodeDiscovery autoDetect()
      Automatically detects the execution environment and returns an appropriate NodeDiscovery implementation.

      Detection priority:

      1. Slurm (checks SLURM_JOB_NODELIST)
      2. Kubernetes (checks POD_NAME and KUBERNETES_SERVICE_HOST)
      3. Grid Engine (checks PE_HOSTFILE)
      Returns:
      a NodeDiscovery implementation for the detected environment
      Throws:
      IllegalStateException - if no supported environment is detected
    • autoDetect

      public static NodeDiscovery autoDetect(int port)
      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

      public static DistributedActorSystem createDistributedSystem(int port) throws IOException
      Creates a DistributedActorSystem with automatic node discovery and registration.

      This convenience method:

      1. Auto-detects the environment
      2. Creates a DistributedActorSystem
      3. 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

      public static DistributedActorSystem createDistributedSystem() throws IOException
      Creates a DistributedActorSystem with default port 8080.
      Returns:
      a fully configured DistributedActorSystem
      Throws:
      IOException - if the HTTP server cannot be created