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 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
    • validateDFCN

      public void validateDFCN()
    • 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.