Search in sources :

Example 1 with Lifecycle

use of com.github.robozonky.app.runtime.Lifecycle in project robozonky by RoboZonky.

the class App method execute.

private static ReturnCode execute(final InvestmentMode mode) {
    App.SHUTDOWN_HOOKS.register(() -> Optional.of((r) -> Scheduler.inBackground().close()));
    Events.fire(new RoboZonkyStartingEvent());
    try {
        ensureLiveness();
        Scheduler.inBackground().submit(new UpdateMonitor(), Duration.ofDays(1));
        App.SHUTDOWN_HOOKS.register(new Management(LIFECYCLE));
        final String sessionName = Events.getSessionInfo().flatMap(SessionInfo::getName).orElse(null);
        App.SHUTDOWN_HOOKS.register(new RoboZonkyStartupNotifier(sessionName));
        return mode.apply(LIFECYCLE);
    } catch (final Throwable t) {
        LOGGER.error("Caught unexpected exception, terminating daemon.", t);
        return ReturnCode.ERROR_UNEXPECTED;
    }
}
Also used : RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) SystemExitServiceLoader(com.github.robozonky.util.SystemExitServiceLoader) Scheduler(com.github.robozonky.util.Scheduler) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) UpdateMonitor(com.github.robozonky.app.version.UpdateMonitor) CommandLine(com.github.robozonky.app.configuration.CommandLine) Charset(java.nio.charset.Charset) Locale(java.util.Locale) Duration(java.time.Duration) Management(com.github.robozonky.app.management.Management) SystemExitService(com.github.robozonky.util.SystemExitService) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMode(com.github.robozonky.app.configuration.InvestmentMode) RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) UpdateMonitor(com.github.robozonky.app.version.UpdateMonitor) Management(com.github.robozonky.app.management.Management)

Example 2 with Lifecycle

use of com.github.robozonky.app.runtime.Lifecycle in project robozonky by RoboZonky.

the class LifecycleTest method version.

@Test
void version() {
    final Lifecycle l = mock(Lifecycle.class);
    when(l.getZonkyApiVersion()).thenReturn(Optional.empty());
    final Runtime r = new Runtime(l);
    assertThat(r.getZonkyApiVersion()).isEqualTo("N/A");
}
Also used : Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Test(org.junit.jupiter.api.Test)

Example 3 with Lifecycle

use of com.github.robozonky.app.runtime.Lifecycle in project robozonky by RoboZonky.

the class LifecycleTest method shutdown.

@Test
void shutdown() {
    final Lifecycle l = mock(Lifecycle.class);
    final Runtime r = new Runtime(l);
    r.stopDaemon();
    verify(l).resumeToShutdown();
}
Also used : Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Test(org.junit.jupiter.api.Test)

Example 4 with Lifecycle

use of com.github.robozonky.app.runtime.Lifecycle in project robozonky by RoboZonky.

the class ManagementTest method registerAndUnregister.

@Test
void registerAndUnregister() {
    final int beanCountBeforeRegister = ManagementTest.SERVER.getMBeanCount();
    final Management m = new Management(new Lifecycle());
    // register the mbeans
    final Optional<Consumer<ShutdownHook.Result>> hook = m.get();
    final int beanCountAfterRegister = ManagementTest.SERVER.getMBeanCount();
    assertSoftly(softly -> {
        softly.assertThat(hook).isPresent();
        softly.assertThat(beanCountAfterRegister).isEqualTo(beanCountBeforeRegister + MBean.values().length);
    });
    // unregister the mbeans
    hook.get().accept(new ShutdownHook.Result(ReturnCode.OK, null));
    final int beanCountAfterUnregister = ManagementTest.SERVER.getMBeanCount();
    assertThat(beanCountAfterUnregister).isEqualTo(beanCountBeforeRegister);
}
Also used : Consumer(java.util.function.Consumer) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) ShutdownHook(com.github.robozonky.app.ShutdownHook) Test(org.junit.jupiter.api.Test)

Aggregations

Lifecycle (com.github.robozonky.app.runtime.Lifecycle)4 Test (org.junit.jupiter.api.Test)3 ReturnCode (com.github.robozonky.api.ReturnCode)1 RoboZonkyStartingEvent (com.github.robozonky.api.notifications.RoboZonkyStartingEvent)1 SessionInfo (com.github.robozonky.api.notifications.SessionInfo)1 ShutdownHook (com.github.robozonky.app.ShutdownHook)1 CommandLine (com.github.robozonky.app.configuration.CommandLine)1 InvestmentMode (com.github.robozonky.app.configuration.InvestmentMode)1 Management (com.github.robozonky.app.management.Management)1 UpdateMonitor (com.github.robozonky.app.version.UpdateMonitor)1 Scheduler (com.github.robozonky.util.Scheduler)1 SystemExitService (com.github.robozonky.util.SystemExitService)1 SystemExitServiceLoader (com.github.robozonky.util.SystemExitServiceLoader)1 Charset (java.nio.charset.Charset)1 Duration (java.time.Duration)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1