If you've done user interface or even Node.js programming, you're probably familiar with the concept of an event loop. Each Hobson plugin has its own event loop referred to as the plugin event loop. This is a single thread that is responsible for delivering events to your plugin when they occur. Events are delivered by the Hobson runtime to your plugin via lifecycle callback methods that it invokes when the event occurs.
Any methods in the HobsonPluginRuntime
interface that start with the prefix "on" are lifecycle callbacks and will always be invoked by the event loop thread.
Name | Description |
---|---|
onStartup | Invoked at plugin startup after all dependencies (including all manager instances) have been injected |
onShutdown | Invoked when the plugin is being shutdown |
onRefresh | Invoked every x number of seconds where x is the value > 0 returned from getRefreshInterval() . |
onPluginConfigurationUpdate | Invoked when the plugin configuration has been changed |
onDeviceConfigurationUpdate | Invoked when the configuration for one of the plugin's devices has been changed |
There are some distinct advantages to the event loop approach:
There are also some disadvantages to this approach:
Even with its disadvantages, the plugin event loop makes writing plugins much simpler and less error-prone for plugin developers.