improve AutoWiringModule so that you don't have to super.configure()
authorMichael Vorburger <mike@vorburger.ch>
Fri, 21 Dec 2018 12:48:45 +0000 (13:48 +0100)
committerMichael Vorburger <mike@vorburger.ch>
Wed, 1 Jul 2020 23:38:05 +0000 (01:38 +0200)
also made it an AbstractCheckedModule while at it

Signed-off-by: Michael Vorburger <mike@vorburger.ch>
src/main/java/org/opendaylight/infrautils/inject/guice/AutoWiringModule.java
src/main/java/org/opendaylight/netvirt/simple/NetvirtModule.java
src/main/java/org/opendaylight/openflowplugin/simple/OpenFlowPluginModule.java

index 00993814755674cb4e06ede69e91e3c51a956b52..d6e5f655308be3ac5f49bced19f2d3a721cad835 100644 (file)
@@ -7,15 +7,15 @@
  */
 package org.opendaylight.infrautils.inject.guice;
 
-import com.google.inject.AbstractModule;
 import java.util.Optional;
+import org.opendaylight.infrautils.inject.guice.testutils.AbstractCheckedModule;
 
 /**
  * Guice Module with classpath scanning based autowiring.
  *
  * @author Michael Vorburger.ch
  */
-public class AutoWiringModule extends AbstractModule {
+public class AutoWiringModule extends AbstractCheckedModule {
 
     protected final GuiceClassPathBinder classPathBinder;
     private final Optional<String> packagePrefix;
@@ -25,13 +25,18 @@ public class AutoWiringModule extends AbstractModule {
         this.packagePrefix = Optional.of(packagePrefix);
     }
 
+    @Deprecated // TODO Remove this, it makes little sense and should ultimately not really be required anymore
     protected AutoWiringModule(GuiceClassPathBinder classPathBinder) {
         this.classPathBinder = classPathBinder;
         this.packagePrefix = Optional.empty();
     }
 
     @Override
-    protected void configure() {
+    protected final void checkedConfigure() throws Exception {
         packagePrefix.ifPresent(prefix -> classPathBinder.bindAllSingletons(prefix, binder()));
+        configureMore();
+    }
+
+    protected void configureMore() throws Exception {
     }
 }
index 0e8da8c0c232eaacc396d46145a691ea87000504..c3b80d5a01bdab85a39e9bc3ecce4a1345b0dfa6 100644 (file)
@@ -18,7 +18,7 @@ public class NetvirtModule extends AutoWiringModule {
     }
 
     @Override
-    protected void configure() {
+    protected void configureMore() {
         install(new GeniusModule(classPathBinder));
 
         install(new AclServiceModule());
index a7a507d5e957a140a83c46fb531fb5564e5ed3e2..3f40e3666d88a338821e20de6541c09f4a658a1d 100644 (file)
@@ -32,9 +32,7 @@ public class OpenFlowPluginModule extends AutoWiringModule {
     }
 
     @Override
-    protected void configure() {
-        super.configure(); // this does the auto-wiring
-
+    protected void configureMore() {
         // TODO curious that this is needed despite SwitchConnectionProviderFactoryImpl being annotated?!
         bind(SwitchConnectionProviderFactory.class).to(SwitchConnectionProviderFactoryImpl.class);
     }