Class MainModuleEngineImpl
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ScheduledExecutorServiceThe single thread every callback runs on.protected ScheduledFuture<?> Tracks the repeating task that drives every registered callback, cancelled byclean().protected booleanIstrueif the Engine is initialized.final LoggerThe logger the engine writes its own diagnostics to. -
Constructor Summary
ConstructorsConstructorDescriptionCreates the engine and brings the whole module graph up. -
Method Summary
Modifier and TypeMethodDescription<E> voidcallDependents(String name, Class<E> moduleInitializerClass, Consumer<E> onInitialize, Logger logger) Invokes every entrypoint registered under the given name, concurrently, and waits for all of them.voidclean()Stops the callback loop, releases every callback, and then shuts the callback executor down.Returns the console handler used for the Curved Spacetime Loggers.Returns the loader this engine resolves entrypoints through.intgetFPS()Returns how many times per second the callback loop runs.Returns the level every module logger is set to.booleanReturns whether this engine has finished initializing.registerMainCallback(MainCallback mainCallback) Registers scene-independent work and initialises it on the callback thread.voidregisterScene(Scene scene) Adds a scene and gives every registered generator a callback for it.registerSceneCallbackGenerator(Function<Scene, SceneCallback> sceneCallbackGenerator) Registers a factory that produces one callback per scene.voidPrepares the loader and runs every module'smainentrypoint.voidthrowError(Throwable t, String message) Logs a failure atSEVEREand stops the engine.
-
Field Details
-
logger
The logger the engine writes its own diagnostics to. -
callbackExecutor
The single thread every callback runs on. -
callbackLoopHandler
Tracks the repeating task that drives every registered callback, cancelled byclean(). -
initialized
protected boolean initializedIstrueif the Engine is initialized. Note that this doesn't mean all callbacks are registered, As a callback can be registered at any time and is registered asynchronously.
-
-
Constructor Details
-
MainModuleEngineImpl
Creates the engine and brings the whole module graph up.Loads the main configuration, registers the initial scene, runs every
mainentrypoint, and starts the callback loop at the configured frame rate.- Parameters:
loader- the loader that resolves module entrypoints- Throws:
RuntimeException- if the main configuration cannot be loaded, or if any module's entrypoint fails
-
-
Method Details
-
registerScene
Description copied from class:EngineAdds a scene and gives every registered generator a callback for it.- Specified by:
registerScenein classEngine- Parameters:
scene- the scene to add
-
runEntrypoints
public void runEntrypoints()Description copied from class:EnginePrepares the loader and runs every module'smainentrypoint.- Specified by:
runEntrypointsin classEngine
-
callDependents
public <E> void callDependents(String name, Class<E> moduleInitializerClass, Consumer<E> onInitialize, Logger logger) throws Throwable Description copied from class:EngineInvokes every entrypoint registered under the given name, concurrently, and waits for all of them.The pool this uses is unbounded, and must remain so. The dependency handshake blocks a consumer in
TransferQueue.takewhile its producer is still to run, so a producer and its consumer have to be runnable at the same time; a bounded pool deadlocks as soon as its threads fill with consumers whose producers are still queued.The first entrypoint to fail aborts the whole call rather than leaving a half-initialized module graph running.
- Specified by:
callDependentsin classEngine- Type Parameters:
E- the entrypoint type- Parameters:
name- the entrypoint name to invoke, such asmainmoduleInitializerClass- the type registered entrypoints must be assignable toonInitialize- the action to apply to each entrypointlogger- the logger to trace dispatch through- Throws:
Throwable- whatever the first failing entrypoint threw
-
getCurvedSpacetimeLoader
Description copied from class:EngineReturns the loader this engine resolves entrypoints through.- Overrides:
getCurvedSpacetimeLoaderin classEngine- Returns:
- the loader
-
registerMainCallback
Description copied from class:EngineRegisters scene-independent work and initialises it on the callback thread.- Specified by:
registerMainCallbackin classEngine- Parameters:
mainCallback- the callback to register- Returns:
- the completable future generated for this task
-
registerSceneCallbackGenerator
public CompletableFuture<Void> registerSceneCallbackGenerator(Function<Scene, SceneCallback> sceneCallbackGenerator) Description copied from class:EngineRegisters a factory that produces one callback per scene.The generator is applied to every scene that exists now, and to each one registered later, so a module never has to track scenes itself.
- Specified by:
registerSceneCallbackGeneratorin classEngine- Parameters:
sceneCallbackGenerator- the factory producing a callback for a given scene- Returns:
- the completable future generated for this task
-
clean
-
throwError
Description copied from class:EngineLogs a failure atSEVEREand stops the engine.- Specified by:
throwErrorin classEngine- Parameters:
t- the failure to logmessage- the message to log it with
-
getConsoleHandler
Description copied from class:EngineReturns the console handler used for the Curved Spacetime Loggers.- Specified by:
getConsoleHandlerin classEngine- Returns:
- the console handler
-
isInitialized
public boolean isInitialized()Description copied from class:EngineReturns whether this engine has finished initializing.That does not mean every callback is registered: a callback can be registered at any time, and registration is asynchronous.
- Specified by:
isInitializedin classEngine- Returns:
trueif the engine is initialized
-
getLoggerLevel
Description copied from class:EngineReturns the level every module logger is set to.- Specified by:
getLoggerLevelin classEngine- Returns:
- the logger level from this engine's configuration
-
getFPS
-