MicroUtils/startup/launcher
2023-01-14 13:22:07 +06:00
..
src improvements in microutils 2023-01-14 13:22:07 +06:00
build.gradle upgrades and filling of README 2022-12-15 10:26:31 +06:00
README.md upgrades and filling of README 2022-12-15 10:26:31 +06:00

Startup Plugin Launcher

This module contains tools to start your plugin system.

Config

Base config is pretty simple:

{
    "plugins": [
        "dev.inmo.micro_utils.startup.launcher.HelloWorldPlugin"
    ]
}

So, "dev.inmo.micro_utils.startup.launcher.HelloWorldPlugin" is the fully qualified name of plugin you wish to be included in the server.

JS note: In JS there are no opportunity to determine object type by its full name. Because of it, in JS developers should prefer to use Config in their kotlin code directly instead of json config passing. More info see in JS section

JVM

For JVM target you may use main class by path: dev.inmo.micro_utils.startup.launcher.MainKt

It is expected, that you will pass the main ONE argument with path to the config json. Sample of launching:

./gradlew run --args="sample.config.json"

Content of sample.config.json described in Config section.

You may build runnable app using:

./gradlew assembleDist

In that case in build/distributions folder you will be able to find zip and tar files with all required tools for application running (via their bin/app_name binary). In that case yoy will not need to pass --args=... and launch will look like ./bin/app_name sample.config.json

JS

In JS for starting of your plugins app, you should use PluginsStarter in your code:

PluginsStarter.startPlugins(
    Config(HelloWorldPlugin)
)

Config here is deserialized variant from Config section. As was said in Config section, in JS there is no way to find classes/objects by their full qualifiers. Because of it you should use some way to register your plugins in StartPluginSerializer or use the code like in the snippet above: there plugins will be registered automatically.

In case you wish to register your plugins manually and run server from config, you should use one of the ways to register plugin on start.

Sample with EagerInitialization: Kotlin JS doc about lazy initialization, @EagerInitialization docs:

@ExperimentalStdlibApi
@EagerInitialization
val plugin = createStartupPluginAndRegister("PluginNameToUseInConfig") {
    // Your plugin creation. For example:
    HelloWorldPlugin
}

So, in that case you will be able to load plugins list as JsonObject from anywhere and start plugins app with it:

PluginsStarter.startPlugins(
    jsonObject
)

It will load HelloWorldPlugin if jsonObject have next content:

{
    "plugins": [
        "PluginNameToUseInConfig"
    ]
}