public BootLogger getBootLogger() { return getInstance(BootLogger.class); }
/** * A convenience shortcut for the tests that are interested in command outcome, not in the runtime state. This * code is equivalent to <code>createRuntime().run()</code>. * * @return an outcome of the application command. * @since 0.25 */ public CommandOutcome run() { return createRuntime().run(); } }
/** * Executes Bootique runtime shutdown, allowing all interested DI services to perform cleanup. * * @since 0.12 */ public void shutdown() { ShutdownManager shutdownManager = injector.getInstance(ShutdownManager.class); BootLogger logger = getBootLogger(); shutdown(shutdownManager, logger); }
@Override protected void after() { Collection<BQRuntime> localRuntimes = this.runtimes; if (localRuntimes != null) { localRuntimes.forEach(runtime -> { try { runtime.shutdown(); } catch (Exception e) { // ignore... } }); } }
private BQRuntime createRuntime(Injector injector) { return new BQRuntime(injector); }
/** * @return a String representation of CLI arguments array * @deprecated since 0.23 this method is unused by Bootique. */ @Deprecated public String getArgsAsString() { return Arrays.asList(getArgs()).stream().collect(joining(" ")); }
/** * Registers a JVM shutdown hook that is delegated to {@link ShutdownManager}. * * @see Bootique#exec() * @since 0.11 * @deprecated since 0.23 unused as {@link Bootique} class handles JVM-level shutdown events. BQRuntime should not * get involved in that. */ @Deprecated public void addJVMShutdownHook() { // resolve all Injector services needed for shutdown eagerly and outside // shutdown thread to ensure that shutdown hook will not fail due to // misconfiguration, etc. ShutdownManager shutdownManager = injector.getInstance(ShutdownManager.class); BootLogger logger = getBootLogger(); Runtime.getRuntime().addShutdownHook(new Thread("bootique-shutdown") { @Override public void run() { shutdown(shutdownManager, logger); } }); }
public void stop() { runtime.shutdown(); // must interrupt execution (using "shutdown()" is not enough to stop // Jetty for instance executor.shutdownNow(); try { executor.awaitTermination(3, TimeUnit.SECONDS); logger.stderr("Daemon runtime stopped..."); } catch (InterruptedException e) { logger.stderr("Interrupted while waiting for shutdown", e); } } }
private BQRuntime createRuntime(Injector injector) { return new BQRuntime(injector); }
/** * Returns a DI-bound instance of a given class, throwing if this class is not explicitly bound in DI. * * @param <T> a type of the instance to return. * @param type a class or interface bound in DI. * @return a DI-bound instance of a given type. * @since 0.12 */ public <T> T getInstance(Class<T> type) { return getInstance(Key.get(type)); }
public void start() { this.executor.submit(() -> outcome = runtime.run()); checkStartupSucceeded(startupTimeout, startupTimeoutTimeUnit); }
/** * Executes Bootique runtime shutdown, allowing all interested DI services to perform cleanup. * * @since 0.12 */ public void shutdown() { ShutdownManager shutdownManager = injector.getInstance(ShutdownManager.class); BootLogger logger = getBootLogger(); shutdown(shutdownManager, logger); }
@Override public void run() { shutdown(shutdownManager, logger); } });
/** * Locates internal {@link Runner} and calls its run method. * * @return outcome of the runner execution. * @since 0.23 */ public CommandOutcome run() { return getInstance(Runner.class).run(); }
Runtime.getRuntime().addShutdownHook(shutdownThread); try { o = createRuntime().run();
/** * Verifies that runtime contains expected modules. * * @param runtime a Bootique runtime whose contents we are testing. * @param expectedModules a vararg array of expected module types. */ @SafeVarargs public static void testModulesLoaded(BQRuntime runtime, Class<? extends Module>... expectedModules) { final ModulesMetadata modulesMetadata = runtime.getInstance(ModulesMetadata.class); final List<String> actualModules = modulesMetadata .getModules() .stream() .map(ModuleMetadata::getName) .collect(toList()); final String[] expectedModuleNames = Stream.of(expectedModules) .map(Class::getSimpleName) .toArray(String[]::new); // Using class names for checking module existing - weak. assertThat(actualModules, hasItems(expectedModuleNames)); } }
/** Run the batch compiler. * * <p>This function runs the compiler and exits with the return code. * * @param args the command line arguments. * @return the exit code. */ public int runCompiler(String... args) { try { final BQRuntime runtime = createRuntime(args); final CommandOutcome outcome = runtime.run(); if (!outcome.isSuccess() && outcome.getException() != null) { Logger.getRootLogger().error(outcome.getMessage(), outcome.getException()); } return outcome.getExitCode(); } catch (ProvisionException exception) { final Throwable ex = Throwables.getRootCause(exception); if (ex != null) { Logger.getRootLogger().error(ex.getLocalizedMessage()); } else { Logger.getRootLogger().error(exception.getLocalizedMessage()); } } catch (Throwable exception) { Logger.getRootLogger().error(exception.getLocalizedMessage()); } return Constants.ERROR_CODE; }
protected void testMetadata() { testWithFactory(testFactory -> { // must auto-load modules to ensure all tested module dependencies are present... BQRuntime runtime = testFactory.app().autoLoadModules().createRuntime(); BQModuleProvider provider = matchingProvider(); String providerName = provider.name(); // loading metadata ensures that all annotations are properly applied... Optional<ModuleMetadata> moduleMetadata = runtime .getInstance(ModulesMetadata.class) .getModules() .stream() .filter(mmd -> providerName.equals(mmd.getProviderName())) .findFirst(); assertTrue("No module metadata available for provider: '" + providerName + "'", moduleMetadata.isPresent()); moduleMetadata.get().getConfigs(); }); }
Runtime.getRuntime().addShutdownHook(shutdownThread); try { o = createRuntime().run();
public BootLogger getBootLogger() { return getInstance(BootLogger.class); }