Class Engine
java.lang.Object
com.blackrook.engine.Engine
The main engine, created as the centerpoint of the communication between components
or as a main mediator between system components.
- Author:
- Matthew Tropiano
-
Method Summary
Modifier and TypeMethodDescriptionvoidconsolePrint(Object message) Prints a message to the console, which involves sending a message to all of the engine's registered console listeners.static EnginecreateEngine(EngineConfig config) Creates the Engine and prepares all of its singletons and starts stuff up and returns the instance.<T> TgetElement(Class<T> clazz) Creates or gets an engine singleton component by class.<T extends EngineResource>
TgetResource(Class<T> clazz, String name) Creates or gets an engine resource by class and name.<T extends EngineResource>
EngineResourceSet.ResourceSet<T> getResourceSet(Class<T> clazz) Creates or gets an engine resource set by class.voidHandles an uncaught, fatal exception and initiates engine shutdown.voidLoads user and global settings from persistent storage and sets element properties.booleanrestartDevice(String name) Restarts an engine device.voidSaves user and global settings to persistent storage.voidshutDown()Initiates engine shutdown.voidshutDown(int status) Initiates engine shutdown.
-
Method Details
-
createEngine
Creates the Engine and prepares all of its singletons and starts stuff up and returns the instance.- Parameters:
config- the engine configuration to use.- Returns:
- the new Engine instance.
-
getElement
Creates or gets an engine singleton component by class.- Type Parameters:
T- the return type.- Parameters:
clazz- the class to create/retrieve.- Returns:
- the corresponding singleton class or null if not found.
-
getResource
Creates or gets an engine resource by class and name.- Type Parameters:
T- the return type.- Parameters:
clazz- the class to use.name- the name of the resource.- Returns:
- the corresponding resource or null if not found.
-
getResourceSet
Creates or gets an engine resource set by class.- Type Parameters:
T- the return type.- Parameters:
clazz- the class to use.- Returns:
- the corresponding set or null if not found.
-
consolePrint
Prints a message to the console, which involves sending a message to all of the engine's registered console listeners.- Parameters:
message- the message (converted to string) to send.
-
saveSettings
public void saveSettings()Saves user and global settings to persistent storage. Calls the following:EngineSettingsListener.onSaveUserSettings(Properties),EngineSettingsListener.onSaveGlobalSettings(Properties),EngineConsole.saveUserVariables(Properties),EngineConsole.saveGlobalVariables(Properties) -
loadSettings
public void loadSettings()Loads user and global settings from persistent storage and sets element properties. Calls the following:EngineSettingsListener.onLoadUserSettings(Properties),EngineSettingsListener.onLoadGlobalSettings(Properties),EngineConsole.loadUserVariables(Properties),EngineConsole.loadGlobalVariables(Properties) -
restartDevice
Restarts an engine device.- Parameters:
name- the name of the device.- Returns:
- true if successful, false if not.
-
handleException
Handles an uncaught, fatal exception and initiates engine shutdown.The ticker is stopped, all devices have
EngineDevice.destroyDevice()called on them, all listeners haveEngineShutdownListener.onUnexpectedEngineShutDown(Throwable)called on them, and tells the JVM to exit.- Parameters:
t- the throwable that caused this to be called.
-
shutDown
public void shutDown()Initiates engine shutdown.The ticker is stopped, all listeners have
EngineShutdownListener.onEngineShutdown()called on them, all settings are saved, all devices haveEngineDevice.destroyDevice()called on them, and tells the JVM to exit.Convenience method for
shutDown(0);- See Also:
-
shutDown
public void shutDown(int status) Initiates engine shutdown.The ticker is stopped, all listeners have
EngineShutdownListener.onEngineShutdown()called on them, all settings are saved, all devices haveEngineDevice.destroyDevice()called on them, and tells the JVM to exit.- Parameters:
status- the status code to return upon program completion (aka "errorlevel" on some OSes).
-