Package com.framed.orchestrator
Class Manager
java.lang.Object
com.framed.orchestrator.Manager
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidinstantiate(String classType) Instantiates all services of the specified type from the configuration.voidStops the service with the specified ID.voidstopAll()Stops all active services managed by this instance.void
-
Constructor Details
-
Manager
Creates a newManagerwith the given configuration and event bus.- Parameters:
config- the JSON configuration containing service definitionseventBus- the event bus for inter-service communication
-
-
Method Details
-
instantiate
Instantiates all services of the specified type from the configuration.The configuration must contain an array under the given
classTypekey, 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
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.
-