Introduce lifecycle to runtime beans registrator in config-manager
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / dependencyresolver / ModuleInternalTransactionalInfo.java
index e9f573a05def40ec079dc3a45522698358ed8ee0..771cddd442ef6210b234472e4d29305e35839a0a 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.controller.config.manager.impl.dependencyresolver;
 
+import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.manager.impl.ModuleInternalInfo;
 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
@@ -14,23 +17,23 @@ import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXR
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.opendaylight.yangtools.concepts.Identifiable;
-
-import javax.annotation.Nullable;
+import org.osgi.framework.BundleContext;
 
 public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdentifier> {
     private final ModuleIdentifier name;
     private final Module proxiedModule, realModule;
     private final ModuleFactory moduleFactory;
-    @Nullable
-    private final ModuleInternalInfo maybeOldInternalInfo;
+
     private final TransactionModuleJMXRegistration transactionModuleJMXRegistration;
     private final boolean isDefaultBean;
+    private final BundleContext bundleContext;
+    @Nullable private ModuleInternalInfo maybeOldInternalInfo;
 
     public ModuleInternalTransactionalInfo(ModuleIdentifier name, Module proxiedModule,
                                            ModuleFactory moduleFactory,
                                            ModuleInternalInfo maybeOldInternalInfo,
                                            TransactionModuleJMXRegistration transactionModuleJMXRegistration,
-                                           boolean isDefaultBean, Module realModule) {
+                                           boolean isDefaultBean, Module realModule, BundleContext bundleContext) {
         this.name = name;
         this.proxiedModule = proxiedModule;
         this.moduleFactory = moduleFactory;
@@ -38,6 +41,7 @@ public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdent
         this.transactionModuleJMXRegistration = transactionModuleJMXRegistration;
         this.isDefaultBean = isDefaultBean;
         this.realModule = realModule;
+        this.bundleContext = bundleContext;
     }
 
 
@@ -54,7 +58,7 @@ public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdent
         return new DestroyedModule(name, oldModule.getInstance(),
                 maybeOldInternalInfo.getModuleJMXRegistrator(),
                 maybeOldInternalInfo.getOsgiRegistration(),
-                maybeOldInternalInfo.getOrderingIdx());
+                maybeOldInternalInfo.getOrderingIdx(), maybeOldInternalInfo.getRuntimeBeanRegistrator());
     }
 
 
@@ -66,12 +70,13 @@ public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdent
         return moduleFactory;
     }
 
-    @Nullable
-    public ModuleInternalInfo getOldInternalInfo() {
-        if (maybeOldInternalInfo == null) {
-            throw new NullPointerException();
-        }
-        return maybeOldInternalInfo;
+    @Nonnull public ModuleInternalInfo getOldInternalInfo() {
+        return Preconditions.checkNotNull(maybeOldInternalInfo);
+    }
+
+    public void clearOldInternalInfo() {
+        Preconditions.checkState(maybeOldInternalInfo != null, "No old internal info present");
+        maybeOldInternalInfo = null;
     }
 
     public TransactionModuleJMXRegistration getTransactionModuleJMXRegistration() {
@@ -90,4 +95,8 @@ public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdent
     public Module getRealModule() {
         return realModule;
     }
+
+    public BundleContext getBundleContext() {
+        return bundleContext;
+    }
 }