Class MagicRuntime
java.lang.Object
dev.ua.theroer.magicutils.bootstrap.MagicRuntime
- All Implemented Interfaces:
AutoCloseable
Shared runtime container for MagicUtils-powered plugins and mods.
The runtime tracks core services, exposes a lightweight typed component registry, and owns shutdown actions/resources that should be cleaned up when the platform stops.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription<C, T extends AutoCloseable>
MagicRuntimeConfigBinding<C, T> bindConfig(String name, Class<C> configClass, Function<C, ? extends T> factory, String... sections) Creates a config-aware managed resource binding that rebuilds the resource when the target config changes.static MagicRuntime.Builderbuilder(Platform platform, ConfigManager configManager, LoggerCore logger) Creates a builder for a runtime rooted in the given core services.voidclose()Returns a snapshot of registered typed components.Returns the config manager owned by the runtime.<T> Optional<T> findComponent(Class<T> type) Returns a component by exact or assignable type.findNamedComponent(String name) Returns a named component by name.<T> Optional<T> findNamedComponent(String name, Class<T> type) Returns a named component when it matches the requested type.booleanisClosed()Returns true when the runtime has already been closed.@Nullable LanguageManagerReturns the language manager when one was configured.logger()Returns the logger core.<T extends AutoCloseable>
TRegisters a closeable resource.Returns a snapshot of named components registered in the runtime.Registers a shutdown action.onStateChanged(Runnable listener) Registers a listener that is invoked whenever runtime component state changes.platform()Returns the platform adapter.<T> TputComponent(Class<T> type, T component) Registers or replaces a typed component.<T> TputNamedComponent(String name, T component) Registers or replaces a named component.@Nullable ObjectremoveNamedComponent(String name) Removes a named component.<T> TrequireComponent(Class<T> type) Returns a component or throws when missing.<T> TrequireNamedComponent(String name, Class<T> type) Returns a named component or throws when missing.<T extends AutoCloseable>
MagicRuntimeResource<T> Creates a managed runtime resource handle.<T extends AutoCloseable>
MagicRuntimeResource<T> Creates a managed runtime resource handle with an initial resource.
-
Method Details
-
builder
public static MagicRuntime.Builder builder(Platform platform, ConfigManager configManager, LoggerCore logger) Creates a builder for a runtime rooted in the given core services.- Parameters:
platform- platform adapterconfigManager- config managerlogger- logger core- Returns:
- builder instance
-
platform
-
configManager
Returns the config manager owned by the runtime.- Returns:
- config manager
-
logger
-
languageManager
Returns the language manager when one was configured.- Returns:
- language manager or null
-
components
-
namedComponents
-
isClosed
public boolean isClosed()Returns true when the runtime has already been closed.- Returns:
- closed flag
-
putComponent
Registers or replaces a typed component.- Type Parameters:
T- component type- Parameters:
type- component keycomponent- component instance- Returns:
- the provided component
-
putNamedComponent
Registers or replaces a named component.- Type Parameters:
T- component type- Parameters:
name- component namecomponent- component instance- Returns:
- the provided component
-
removeNamedComponent
-
onStateChanged
Registers a listener that is invoked whenever runtime component state changes.- Parameters:
listener- listener to invoke after component registry updates- Returns:
- runtime for chaining
-
onClose
Registers a shutdown action.- Parameters:
name- debug label for loggingaction- action to run during close- Returns:
- runtime for chaining
-
manage
Registers a closeable resource.- Type Parameters:
T- closeable type- Parameters:
name- debug label for loggingcloseable- closeable resource- Returns:
- the same resource
-
findComponent
-
findNamedComponent
-
findNamedComponent
-
requireComponent
Returns a component or throws when missing.- Type Parameters:
T- component type- Parameters:
type- component type- Returns:
- component instance
-
requireNamedComponent
-
resource
Creates a managed runtime resource handle.- Type Parameters:
T- resource type- Parameters:
name- resource name used for runtime registration- Returns:
- managed resource handle
-
resource
Creates a managed runtime resource handle with an initial resource.- Type Parameters:
T- resource type- Parameters:
name- resource name used for runtime registrationinitial- initial resource, optionally null- Returns:
- managed resource handle
-
bindConfig
public <C, T extends AutoCloseable> MagicRuntimeConfigBinding<C,T> bindConfig(String name, Class<C> configClass, Function<C, ? extends T> factory, String... sections) Creates a config-aware managed resource binding that rebuilds the resource when the target config changes.- Type Parameters:
C- config typeT- resource type- Parameters:
name- resource name used for runtime registrationconfigClass- config class driving the resourcefactory- resource factory receiving the current config instancesections- optional sections that should trigger a rebuild- Returns:
- config-aware managed resource binding
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-