App Context

class bedrock_server_manager.context.AppContext(settings: 'Settings' | None = None, manager: 'BedrockServerManager' | 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 BedrockServerManager, PluginManager, 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]

_manager

Internal storage for the main manager.

Type:

Optional[BedrockServerManager]

_db

Internal storage for the database handler.

Type:

Optional[Database]

_servers

Cache of instantiated server objects.

Type:

Dict[str, BedrockServer]

loop

The asyncio event loop, if set.

Type:

Optional[AbstractEventLoop]

__init__(settings: 'Settings' | None = None, manager: 'BedrockServerManager' | None = None, db: 'Database' | None = None)

Initializes the AppContext.

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

  • manager (Optional[BedrockServerManager]) – Pre-existing manager instance.

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

load()

Loads the application context by initializing the settings and manager.

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, main manager, and plugin manager, allowing configuration changes to take effect without restarting the entire process.

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 manager: BedrockServerManager

Returns the BedrockServerManager instance.

Returns:

The main application manager.

Return type:

BedrockServerManager

Raises:

RuntimeError – If the manager has 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.