App Context

class bedrock_server_manager.context.AppContext(settings: 'Settings' | None = None, db: 'Database' | None = None)

Bases: object

A context object that holds application-wide instances and caches.

The AppContext acts as a central hub for accessing core application components. It manages the lifecycle of singletons like the PluginManager, settings, and database connection. Most properties are lazily initialized to improve startup time and handle dependency resolution order.

_settings

Internal storage for the settings instance.

Type:

Optional[Settings]

_db

Internal storage for the database handler.

Type:

Optional[Database]

_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.

Parameters:
  • settings (Optional[Settings]) – Pre-existing settings instance.

  • db (Optional[Database]) – Pre-existing database instance.

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:

Settings

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:

Database

property plugin_manager: PluginManager

Lazily loads and returns the PluginManager instance.

Returns:

The plugin manager.

Return type:

PluginManager

property task_manager: TaskManager

Lazily loads and returns the TaskManager instance.

Returns:

The task manager for background operations.

Return type:

TaskManager

property connection_manager: ConnectionManager

Lazily loads and returns the ConnectionManager instance.

Returns:

The WebSocket connection manager.

Return type:

ConnectionManager

property resource_monitor: ResourceMonitor

Lazily loads and returns the ResourceMonitor instance.

Returns:

The system resource monitor.

Return type:

ResourceMonitor

property bedrock_process_manager: BedrockProcessManager

Lazily loads and returns the BedrockProcessManager instance.

Returns:

The server process monitor.

Return type:

BedrockProcessManager

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:

BedrockServer

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.