Class Manager

java.lang.Object
com.framed.orchestrator.Manager

public class Manager extends Object
The Manager class is responsible for orchestrating the lifecycle of Service instances based on a JSON configuration. It uses an EventBus for inter-service communication and provides methods to instantiate, stop, and manage services dynamically.

Features:

  • Instantiates services from JSON configuration using Factory.
  • Maintains a registry of active service instances keyed by their IDs.
  • Supports stopping individual services or all services at once.

Usage Example:


 JSONObject config = new JSONObject("""
 {
   "devices": [
     { "id": "sensor1", "type": "TemperatureSensor" },
     { "id": "sensor2", "type": "HumiditySensor" }
   ]
 }
 """);

 EventBus eventBus = new SocketEventBus(new TCPTransport(8080));
 Manager manager = new Manager(config, eventBus);

 // Instantiate all services under "devices"
 manager.instantiate("devices");

 // Stop a specific service
 manager.stop("sensor1");

 // Stop all services
 manager.stopAll();
 

Threading Model: All operations are synchronous and blocking. Service instantiation and stopping occur on the calling thread.

Note: Ensure that the provided configuration contains valid service definitions and that Factory supports the specified types (use the validators in ConfigLoader.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Manager(org.json.JSONObject config, EventBus eventBus)
    Creates a new Manager with the given configuration and event bus.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    instantiate(String classType)
    Instantiates all services of the specified type from the configuration.
    void
    Stops the service with the specified ID.
    void
    Stops all active services managed by this instance.
    void
    Runs all DeploymentValidators discovered on the classpath against the set of instantiated services.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Manager

      public Manager(org.json.JSONObject config, EventBus eventBus)
      Creates a new Manager with the given configuration and event bus.
      Parameters:
      config - the JSON configuration containing service definitions
      eventBus - the event bus for inter-service communication
  • Method Details

    • instantiate

      public void instantiate(String classType)
      Instantiates all services of the specified type from the configuration.

      The configuration must contain an array under the given classType key, where each element is a JSON object representing a service definition.

      Parameters:
      classType - the key in the configuration representing the service type group
    • validate

      public void validate()
      Runs all DeploymentValidators discovered on the classpath against the set of instantiated services. Domain modules contribute validators via ServiceLoader (e.g. the CDSS module's acyclic-reactor-network check), keeping the orchestrator free of any domain dependency.
    • stop

      public void stop(String id)
      Stops the service with the specified ID.
      Parameters:
      id - the ID of the service to stop
    • stopAll

      public void stopAll()
      Stops all active services managed by this instance.