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());
}
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());
}
}
Aggregations