🏗️ Use Rhynodge module and let Guice handle everything main
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Nov 2024 22:08:07 +0000 (23:08 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Nov 2024 22:08:07 +0000 (23:08 +0100)
src/main/java/net/pterodactylus/rhynodge/engine/Starter.java

index 20611c1..ce84b5e 100644 (file)
 package net.pterodactylus.rhynodge.engine;
 
 import java.io.IOException;
 package net.pterodactylus.rhynodge.engine;
 
 import java.io.IOException;
-import java.util.Arrays;
 
 
-import net.pterodactylus.rhynodge.actions.EmailAction;
 import net.pterodactylus.rhynodge.loader.ChainWatcher;
 import net.pterodactylus.rhynodge.loader.ChainWatcher;
-import net.pterodactylus.rhynodge.loader.ChainWatcher.ChainDirectory;
-import net.pterodactylus.rhynodge.states.StateManager.StateDirectory;
 import net.pterodactylus.util.envopt.Parser;
 import net.pterodactylus.util.inject.ObjectBinding;
 
 import net.pterodactylus.util.envopt.Parser;
 import net.pterodactylus.util.inject.ObjectBinding;
 
@@ -47,27 +43,17 @@ public class Starter {
        public static void main(String... arguments) throws IOException {
                Options options = Parser.fromSystemEnvironment().parseEnvironment(Options::new);
                logger.info("Options: " + options);
        public static void main(String... arguments) throws IOException {
                Options options = Parser.fromSystemEnvironment().parseEnvironment(Options::new);
                logger.info("Options: " + options);
-               EmailAction errorEmailAction =
-                               createErrorEmailAction(options.smtpHostname, options.errorEmailSender, options.errorEmailRecipient);
 
 
-               Injector injector = Guice.createInjector(Arrays.asList(
-                               ObjectBinding.forClass(String.class).named("smtpHostname").is(options.smtpHostname),
-                               ObjectBinding.forClass(String.class).named("emailSender").is(options.emailSender),
-                               ObjectBinding.forClass(String.class).named("emailRecipient").is(options.emailRecipient),
-                               ObjectBinding.forClass(StateDirectory.class).is(StateDirectory.of(options.stateDirectory)),
-                               ObjectBinding.forClass(ChainDirectory.class).is(ChainDirectory.of(options.chainDirectory)),
-                               ObjectBinding.forClass(EmailAction.class).is(errorEmailAction)
-               ));
+               Injector injector = Guice.createInjector(
+                               ObjectBinding.forClass(Options.class).shallBe(options),
+                               new RhynodgeModule()
+               );
 
                /* start a watcher. */
                ChainWatcher chainWatcher = injector.getInstance(ChainWatcher.class);
                chainWatcher.startAsync().awaitTerminated();
        }
 
 
                /* start a watcher. */
                ChainWatcher chainWatcher = injector.getInstance(ChainWatcher.class);
                chainWatcher.startAsync().awaitTerminated();
        }
 
-       private static EmailAction createErrorEmailAction(String smtpHostname, String errorEmailSender, String errorEmailRecipient) {
-               return new EmailAction(smtpHostname, errorEmailSender, errorEmailRecipient);
-       }
-
        private static final Logger logger = Logger.getLogger(Starter.class);
 
 }
        private static final Logger logger = Logger.getLogger(Starter.class);
 
 }