Search in sources :

Example 1 with BaseFoundation

use of space.arim.libertybans.bootstrap.BaseFoundation in project LibertyBans by A248.

the class VelocityInitializer method initialize.

BaseFoundation initialize() {
    Platform platform = detectPlatform();
    ProxyServer server = velocityPlugin.server;
    Path folder = velocityPlugin.folder;
    Logger logger = velocityPlugin.logger;
    PluginContainer plugin = server.getPluginManager().fromInstance(velocityPlugin).get();
    Scheduler scheduler = server.getScheduler();
    Executor executor = (cmd) -> scheduler.buildTask(plugin, cmd).schedule();
    Path jarFile = plugin.getDescription().getSource().get();
    LibertyBansLauncher launcher = new LibertyBansLauncher(new Slf4jBootstrapLogger(velocityPlugin.logger), platform, velocityPlugin.folder, executor, jarFile, new VelocityCulpritFinder(server));
    ClassLoader launchLoader = launcher.attemptLaunch().join();
    if (launchLoader == null) {
        logger.warn("Failed to launch LibertyBans");
        return null;
    }
    BaseFoundation base;
    try {
        base = new Instantiator("space.arim.libertybans.env.velocity.VelocityLauncher", launchLoader).invoke(Map.Entry.class, Map.entry(plugin, server), folder);
    } catch (IllegalArgumentException | SecurityException | ReflectiveOperationException ex) {
        logger.warn("Failed to launch LibertyBans", ex);
        return null;
    }
    base.startup();
    return base;
}
Also used : Path(java.nio.file.Path) Platforms(space.arim.libertybans.bootstrap.Platforms) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) LibertyBansLauncher(space.arim.libertybans.bootstrap.LibertyBansLauncher) BaseFoundation(space.arim.libertybans.bootstrap.BaseFoundation) Platform(space.arim.libertybans.bootstrap.Platform) Slf4jBootstrapLogger(space.arim.libertybans.bootstrap.logger.Slf4jBootstrapLogger) Scheduler(com.velocitypowered.api.scheduler.Scheduler) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Map(java.util.Map) Instantiator(space.arim.libertybans.bootstrap.Instantiator) PluginContainer(com.velocitypowered.api.plugin.PluginContainer) Path(java.nio.file.Path) LibertyBansLauncher(space.arim.libertybans.bootstrap.LibertyBansLauncher) BaseFoundation(space.arim.libertybans.bootstrap.BaseFoundation) PluginContainer(com.velocitypowered.api.plugin.PluginContainer) Platform(space.arim.libertybans.bootstrap.Platform) Scheduler(com.velocitypowered.api.scheduler.Scheduler) Slf4jBootstrapLogger(space.arim.libertybans.bootstrap.logger.Slf4jBootstrapLogger) Instantiator(space.arim.libertybans.bootstrap.Instantiator) Logger(org.slf4j.Logger) Slf4jBootstrapLogger(space.arim.libertybans.bootstrap.logger.Slf4jBootstrapLogger) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Executor(java.util.concurrent.Executor)

Example 2 with BaseFoundation

use of space.arim.libertybans.bootstrap.BaseFoundation in project LibertyBans by A248.

the class VelocityPlugin method onProxyShutdown.

@Subscribe
public synchronized void onProxyShutdown(ProxyShutdownEvent evt) {
    BaseFoundation base = this.base;
    this.base = null;
    if (base == null) {
        logger.warn("LibertyBans wasn't launched; check your log for a startup error");
        return;
    }
    base.shutdown();
}
Also used : BaseFoundation(space.arim.libertybans.bootstrap.BaseFoundation) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 3 with BaseFoundation

use of space.arim.libertybans.bootstrap.BaseFoundation in project LibertyBans by A248.

the class JpmsTest method initialize.

@Test
public void initialize() {
    BaseFoundation foundation = assertDoesNotThrow(() -> newLauncher().launch());
    assertNotNull(foundation);
}
Also used : BaseFoundation(space.arim.libertybans.bootstrap.BaseFoundation) Test(org.junit.jupiter.api.Test)

Example 4 with BaseFoundation

use of space.arim.libertybans.bootstrap.BaseFoundation in project LibertyBans by A248.

the class JpmsTest method startupAndShutdown.

@Test
public void startupAndShutdown() {
    // This test is mostly intended to check that the configuration is exported to dazzleconf
    when(handle.createFuturesFactory()).thenReturn(new IndifferentFactoryOfTheFuture());
    when(environment.createListeners()).thenReturn(Set.of());
    when(environment.createAliasCommand(any())).thenReturn(new PlatformListener() {

        @Override
        public void register() {
        }

        @Override
        public void unregister() {
        }
    });
    BaseFoundation foundation = newLauncher().launch();
    assertDoesNotThrow(foundation::startup);
    assertDoesNotThrow(foundation::shutdown);
}
Also used : BaseFoundation(space.arim.libertybans.bootstrap.BaseFoundation) IndifferentFactoryOfTheFuture(space.arim.omnibus.util.concurrent.impl.IndifferentFactoryOfTheFuture) PlatformListener(space.arim.libertybans.core.env.PlatformListener) Test(org.junit.jupiter.api.Test)

Example 5 with BaseFoundation

use of space.arim.libertybans.bootstrap.BaseFoundation in project LibertyBans by A248.

the class ResourceCreator method createSingle.

private Optional<Injector> createSingle(ConfigSpec configSpec, DatabaseInstance database, InstanceKey instanceKey) {
    DatabaseInfo databaseInfo = database.createInfo().orElse(null);
    if (databaseInfo == null) {
        return Optional.empty();
    }
    return Optional.of(store.getOrComputeIfAbsent(instanceKey, (ignore) -> {
        Path tempDirectory = createTempDirectory();
        Injector injector = new InjectorBuilder().bindInstance(Identifier.ofTypeAndNamed(Path.class, "folder"), tempDirectory).bindInstance(ConfigSpec.class, configSpec).bindInstance(DatabaseInfo.class, databaseInfo).bindInstance(DatabaseInstance.class, database).bindInstance(Identifier.ofTypeAndNamed(Instant.class, "testStartTime"), configSpec.unixTime()).addBindModules(new ApiBindModule(), new PillarOneReplacementModule(), new PillarTwoBindModule(), new QuackBindModule()).build();
        BaseFoundation base = injector.request(BaseFoundation.class);
        base.startup();
        return new BaseWrapper(injector, base, tempDirectory);
    }, BaseWrapper.class).injector);
}
Also used : Path(java.nio.file.Path) PillarTwoBindModule(space.arim.libertybans.core.PillarTwoBindModule) BaseFoundation(space.arim.libertybans.bootstrap.BaseFoundation) Instant(java.time.Instant) PillarOneReplacementModule(space.arim.libertybans.core.PillarOneReplacementModule) ApiBindModule(space.arim.libertybans.core.ApiBindModule) QuackBindModule(space.arim.libertybans.it.env.QuackBindModule) Injector(space.arim.injector.Injector) InjectorBuilder(space.arim.injector.InjectorBuilder)

Aggregations

BaseFoundation (space.arim.libertybans.bootstrap.BaseFoundation)5 Path (java.nio.file.Path)2 Test (org.junit.jupiter.api.Test)2 Subscribe (com.velocitypowered.api.event.Subscribe)1 PluginContainer (com.velocitypowered.api.plugin.PluginContainer)1 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)1 Scheduler (com.velocitypowered.api.scheduler.Scheduler)1 Instant (java.time.Instant)1 Map (java.util.Map)1 Executor (java.util.concurrent.Executor)1 Logger (org.slf4j.Logger)1 Injector (space.arim.injector.Injector)1 InjectorBuilder (space.arim.injector.InjectorBuilder)1 Instantiator (space.arim.libertybans.bootstrap.Instantiator)1 LibertyBansLauncher (space.arim.libertybans.bootstrap.LibertyBansLauncher)1 Platform (space.arim.libertybans.bootstrap.Platform)1 Platforms (space.arim.libertybans.bootstrap.Platforms)1 Slf4jBootstrapLogger (space.arim.libertybans.bootstrap.logger.Slf4jBootstrapLogger)1 ApiBindModule (space.arim.libertybans.core.ApiBindModule)1 PillarOneReplacementModule (space.arim.libertybans.core.PillarOneReplacementModule)1