Search in sources :

Example 1 with YamlSnakeYamlConfigurer

use of eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer in project okaeri-platform by OkaeriPoland.

the class OkaeriWebApplication method plan.

@Override
public void plan(@NonNull ExecutionPlan plan) {
    plan.add(PRE_SETUP, new InjectorSetupTask());
    plan.add(PRE_SETUP, (ExecutionTask<OkaeriWebApplication>) platform -> {
        platform.registerInjectable("dataFolder", platform.getDataFolder());
        platform.registerInjectable("jarFile", platform.getFile());
        platform.registerInjectable("logger", platform.getLogger());
        platform.registerInjectable("app", platform);
        platform.registerInjectable("javalin", platform.getJavalin());
        platform.registerInjectable("jetty", Objects.requireNonNull(platform.getJavalin().jettyServer()));
        platform.registerInjectable("placeholders", Placeholders.create(true));
        platform.registerInjectable("defaultConfigurerProvider", (ConfigurerProvider) YamlSnakeYamlConfigurer::new);
        platform.registerInjectable("defaultConfigurerSerdes", new Class[] { SerdesCommons.class, SerdesWeb.class });
        platform.registerInjectable("defaultPlaceholdersFactory", new SimplePlaceholdersFactory());
        platform.registerInjectable("i18nLocaleProvider", new SystemLocaleProvider());
    });
    plan.add(SETUP, new CommandsSetupTask(new OkaeriCommands()));
    plan.add(SETUP, new CreatorSetupTask(ApplicationComponentCreator.class, WebCreatorRegistry.class));
    plan.add(POST_SETUP, new BeanManifestCreateTask());
    plan.add(POST_SETUP, new BeanManifestExecuteTask());
    plan.add(POST_SETUP, new JavalinSetupTask());
    plan.add(POST_SETUP, new PlatformBannerStartupTask());
    plan.add(STARTUP, new JavalinStartTask());
    plan.add(SHUTDOWN, new JavalinShutdownTask());
    plan.add(SHUTDOWN, new PersistenceShutdownTask());
}
Also used : WebCreatorRegistry(eu.okaeri.platform.web.component.WebCreatorRegistry) JavalinShutdownTask(eu.okaeri.platform.web.plan.JavalinShutdownTask) Setter(lombok.Setter) Arrays(java.util.Arrays) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) LoggerFactory(org.slf4j.LoggerFactory) ExecutionPlan(eu.okaeri.platform.core.plan.ExecutionPlan) Injector(eu.okaeri.injector.Injector) Javalin(io.javalin.Javalin) SerdesWeb(eu.okaeri.platform.web.meta.serdes.SerdesWeb) SerdesCommons(eu.okaeri.configs.serdes.commons.SerdesCommons) JavalinStartTask(eu.okaeri.platform.web.plan.JavalinStartTask) OkaeriPlatform(eu.okaeri.platform.core.OkaeriPlatform) SystemLocaleProvider(eu.okaeri.platform.standalone.i18n.SystemLocaleProvider) ExecutionResult(eu.okaeri.platform.core.plan.ExecutionResult) ExecutionTask(eu.okaeri.platform.core.plan.ExecutionTask) SimplePlaceholdersFactory(eu.okaeri.platform.core.placeholder.SimplePlaceholdersFactory) Logger(org.slf4j.Logger) YamlSnakeYamlConfigurer(eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer) NonNull(lombok.NonNull) OkaeriCommands(eu.okaeri.commands.OkaeriCommands) ApplicationComponentCreator(eu.okaeri.platform.standalone.component.ApplicationComponentCreator) File(java.io.File) Objects(java.util.Objects) Placeholders(eu.okaeri.placeholders.Placeholders) ComponentHelper(eu.okaeri.platform.core.component.ComponentHelper) ComponentCreator(eu.okaeri.platform.core.component.creator.ComponentCreator) eu.okaeri.platform.core.plan.task(eu.okaeri.platform.core.plan.task) ConfigurerProvider(eu.okaeri.persistence.document.ConfigurerProvider) JavalinSetupTask(eu.okaeri.platform.web.plan.JavalinSetupTask) ExecutionPhase(eu.okaeri.platform.core.plan.ExecutionPhase) ApplicationComponentCreator(eu.okaeri.platform.standalone.component.ApplicationComponentCreator) ConfigurerProvider(eu.okaeri.persistence.document.ConfigurerProvider) SimplePlaceholdersFactory(eu.okaeri.platform.core.placeholder.SimplePlaceholdersFactory) SerdesCommons(eu.okaeri.configs.serdes.commons.SerdesCommons) OkaeriCommands(eu.okaeri.commands.OkaeriCommands) SystemLocaleProvider(eu.okaeri.platform.standalone.i18n.SystemLocaleProvider) SerdesWeb(eu.okaeri.platform.web.meta.serdes.SerdesWeb) JavalinStartTask(eu.okaeri.platform.web.plan.JavalinStartTask) JavalinShutdownTask(eu.okaeri.platform.web.plan.JavalinShutdownTask) JavalinSetupTask(eu.okaeri.platform.web.plan.JavalinSetupTask) YamlSnakeYamlConfigurer(eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer) WebCreatorRegistry(eu.okaeri.platform.web.component.WebCreatorRegistry)

Example 2 with YamlSnakeYamlConfigurer

use of eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer in project okaeri-platform by OkaeriPoland.

the class ExampleWebApplication method configurePersistence.

// built-in persistence utils
// easy storage for e.g. player properties
// see persistence/PlayerPersistence for details
@Bean(value = "persistence", preload = true)
public DocumentPersistence configurePersistence(@Inject("dataFolder") File dataFolder, TestConfig config) {
    // jdbc drivers may require initialization for jdbc urls to work
    try {
        Class.forName("org.mariadb.jdbc.Driver");
    } catch (ClassNotFoundException ignored) {
    }
    try {
        Class.forName("org.h2.Driver");
    } catch (ClassNotFoundException ignored) {
    }
    // remember that if plugin is not intended to have shared state
    // between multiple instances you must allow users to set persistence's
    // basePath manually or add some other possibility to differ keys
    // otherwise plugin usage would be limited to one instance per one redis
    PersistencePath basePath = PersistencePath.of(config.getStorage().getPrefix());
    // multiple backends are possible with an easy switch
    switch(config.getStorage().getBackend()) {
        case FLAT:
            // specify custom child dir in dataFolder or other custom location
            File storagePath = new File(config.getStorage().getUri());
            return new DocumentPersistence(new FlatPersistence(storagePath, ".yml"), YamlSnakeYamlConfigurer::new, new SerdesWeb());
        case REDIS:
            // construct redis client based on your needs, e.g. using config
            RedisURI redisUri = RedisURI.create(config.getStorage().getUri());
            RedisClient redisClient = RedisClient.create(redisUri);
            // on the redis side thanks to cjson available in lua scripting
            return new DocumentPersistence(new RedisPersistence(basePath, redisClient), JsonSimpleConfigurer::new, new SerdesWeb());
        case MONGO:
            // construct mongo client based on your needs, e.g. using config
            MongoClientURI mongoUri = new MongoClientURI(config.getStorage().getUri());
            MongoClient mongoClient = new MongoClient(mongoUri);
            // validate if uri contains database
            if (mongoUri.getDatabase() == null) {
                throw new IllegalArgumentException("Mongo URI needs to specify the database: " + mongoUri.getURI());
            }
            // it is REQUIRED to use json configurer for the mongo backend
            return new DocumentPersistence(new MongoPersistence(basePath, mongoClient, mongoUri.getDatabase()), JsonSimpleConfigurer::new, new SerdesWeb());
        case MYSQL:
            // setup hikari based on your needs, e.g. using config
            HikariConfig mariadbHikari = new HikariConfig();
            mariadbHikari.setJdbcUrl(config.getStorage().getUri());
            // it is REQUIRED to use json configurer for the mariadb backend
            return new DocumentPersistence(new MariaDbPersistence(basePath, mariadbHikari), JsonSimpleConfigurer::new, new SerdesWeb());
        case H2:
            // setup hikari based on your needs, e.g. using config
            HikariConfig jdbcHikari = new HikariConfig();
            jdbcHikari.setJdbcUrl(config.getStorage().getUri());
            // it is HIGHLY recommended to use json configurer for the jdbc backend
            return new DocumentPersistence(new H2Persistence(basePath, jdbcHikari), JsonSimpleConfigurer::new, new SerdesWeb());
        default:
            throw new RuntimeException("unsupported storage backend: " + config.getStorage().getBackend());
    }
}
Also used : DocumentPersistence(eu.okaeri.persistence.document.DocumentPersistence) FlatPersistence(eu.okaeri.persistence.flat.FlatPersistence) RedisPersistence(eu.okaeri.persistence.redis.RedisPersistence) RedisURI(io.lettuce.core.RedisURI) MongoClientURI(com.mongodb.MongoClientURI) H2Persistence(eu.okaeri.persistence.jdbc.H2Persistence) PersistencePath(eu.okaeri.persistence.PersistencePath) HikariConfig(com.zaxxer.hikari.HikariConfig) RedisClient(io.lettuce.core.RedisClient) MongoClient(com.mongodb.MongoClient) MariaDbPersistence(eu.okaeri.persistence.jdbc.MariaDbPersistence) SerdesWeb(eu.okaeri.platform.web.meta.serdes.SerdesWeb) MongoPersistence(eu.okaeri.persistence.mongo.MongoPersistence) File(java.io.File) JsonSimpleConfigurer(eu.okaeri.configs.json.simple.JsonSimpleConfigurer) YamlSnakeYamlConfigurer(eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer) Bean(eu.okaeri.platform.core.annotation.Bean)

Aggregations

YamlSnakeYamlConfigurer (eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer)2 SerdesWeb (eu.okaeri.platform.web.meta.serdes.SerdesWeb)2 File (java.io.File)2 MongoClient (com.mongodb.MongoClient)1 MongoClientURI (com.mongodb.MongoClientURI)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 OkaeriCommands (eu.okaeri.commands.OkaeriCommands)1 JsonSimpleConfigurer (eu.okaeri.configs.json.simple.JsonSimpleConfigurer)1 SerdesCommons (eu.okaeri.configs.serdes.commons.SerdesCommons)1 Injector (eu.okaeri.injector.Injector)1 PersistencePath (eu.okaeri.persistence.PersistencePath)1 ConfigurerProvider (eu.okaeri.persistence.document.ConfigurerProvider)1 DocumentPersistence (eu.okaeri.persistence.document.DocumentPersistence)1 FlatPersistence (eu.okaeri.persistence.flat.FlatPersistence)1 H2Persistence (eu.okaeri.persistence.jdbc.H2Persistence)1 MariaDbPersistence (eu.okaeri.persistence.jdbc.MariaDbPersistence)1 MongoPersistence (eu.okaeri.persistence.mongo.MongoPersistence)1 RedisPersistence (eu.okaeri.persistence.redis.RedisPersistence)1 Placeholders (eu.okaeri.placeholders.Placeholders)1 OkaeriPlatform (eu.okaeri.platform.core.OkaeriPlatform)1