App Context
- class bedrock_server_manager.context.AppContext(settings: 'Settings' | None = None, db: 'Database' | None = None)
Bases:
objectA context object that holds application-wide instances and caches.
The
AppContextacts as a central hub for accessing core application components. It manages the lifecycle of singletons like thePluginManager, settings, and database connection. Most properties are lazily initialized to improve startup time and handle dependency resolution order.- _servers
Cache of instantiated server objects.
- Type:
Dict[str, BedrockServer]
- _web_server
The running Uvicorn server instance, if available.
- Type:
Optional[Any]
- loop
The asyncio event loop, if set.
- Type:
Optional[AbstractEventLoop]
- __init__(settings: 'Settings' | None = None, db: 'Database' | None = None)
Initializes the AppContext.
- load()
Loads the application context by initializing the settings.
This method should be called early in the application startup phase to ensure core components like the database and settings are ready.
- reload()
Reloads the application context by reloading settings and all components.
This triggers a reload on the settings and plugin manager, allowing configuration changes to take effect without restarting the entire process.
- property api: AppAPI
Lazily loads and returns the API instance.
- Returns:
The internal core API bridge.
- Return type:
AppAPI
- property settings: Settings
Returns the Settings instance.
- Returns:
The global settings object.
- Return type:
- Raises:
RuntimeError – If the settings have not been loaded yet.
- property db: Database
Lazily loads and returns the Database instance.
- Returns:
The database handler.
- Return type:
- property plugin_manager: PluginManager
Lazily loads and returns the PluginManager instance.
- Returns:
The plugin manager.
- Return type:
- property task_manager: TaskManager
Lazily loads and returns the TaskManager instance.
- Returns:
The task manager for background operations.
- Return type:
- property connection_manager: ConnectionManager
Lazily loads and returns the ConnectionManager instance.
- Returns:
The WebSocket connection manager.
- Return type:
- property resource_monitor: ResourceMonitor
Lazily loads and returns the ResourceMonitor instance.
- Returns:
The system resource monitor.
- Return type:
- property bedrock_process_manager: BedrockProcessManager
Lazily loads and returns the BedrockProcessManager instance.
- Returns:
The server process monitor.
- Return type:
- get_server(server_name: str) BedrockServer
Retrieve or create a BedrockServer instance.
- Parameters:
server_name (str) – The name of the server to get.
- Returns:
The requested BedrockServer instance.
- Return type:
- remove_server(server_name: str)
Stops a server, removes it from the process manager, and discards it from the context cache.
- Parameters:
server_name (str) – The name of the server to remove.
- stop_all_servers()
Stops all running servers in the application context cache using the API bridge.