Resolve Bug:807 - Keep ModuleFactory references shutdown purposes.
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / dependencyresolver / ModuleInternalTransactionalInfo.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.config.manager.impl.dependencyresolver;
9
10 import org.opendaylight.controller.config.api.ModuleIdentifier;
11 import org.opendaylight.controller.config.manager.impl.ModuleInternalInfo;
12 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
13 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration;
14 import org.opendaylight.controller.config.spi.Module;
15 import org.opendaylight.controller.config.spi.ModuleFactory;
16 import org.opendaylight.yangtools.concepts.Identifiable;
17
18 import javax.annotation.Nullable;
19 import org.osgi.framework.BundleContext;
20
21 public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdentifier> {
22     private final ModuleIdentifier name;
23     private final Module proxiedModule, realModule;
24     private final ModuleFactory moduleFactory;
25     @Nullable
26     private final ModuleInternalInfo maybeOldInternalInfo;
27     private final TransactionModuleJMXRegistration transactionModuleJMXRegistration;
28     private final boolean isDefaultBean;
29     private final BundleContext bundleContext;
30
31     public ModuleInternalTransactionalInfo(ModuleIdentifier name, Module proxiedModule,
32                                            ModuleFactory moduleFactory,
33                                            ModuleInternalInfo maybeOldInternalInfo,
34                                            TransactionModuleJMXRegistration transactionModuleJMXRegistration,
35                                            boolean isDefaultBean, Module realModule, BundleContext bundleContext) {
36         this.name = name;
37         this.proxiedModule = proxiedModule;
38         this.moduleFactory = moduleFactory;
39         this.maybeOldInternalInfo = maybeOldInternalInfo;
40         this.transactionModuleJMXRegistration = transactionModuleJMXRegistration;
41         this.isDefaultBean = isDefaultBean;
42         this.realModule = realModule;
43         this.bundleContext = bundleContext;
44     }
45
46
47     public boolean hasOldModule() {
48         return maybeOldInternalInfo != null;
49     }
50
51     public DestroyedModule toDestroyedModule() {
52         if (maybeOldInternalInfo == null) {
53             throw new IllegalStateException("Cannot destroy uncommitted module");
54         }
55         DynamicReadableWrapper oldModule = maybeOldInternalInfo
56                 .getReadableModule();
57         return new DestroyedModule(name, oldModule.getInstance(),
58                 maybeOldInternalInfo.getModuleJMXRegistrator(),
59                 maybeOldInternalInfo.getOsgiRegistration(),
60                 maybeOldInternalInfo.getOrderingIdx());
61     }
62
63
64     public Module getProxiedModule() {
65         return proxiedModule;
66     }
67
68     public ModuleFactory getModuleFactory() {
69         return moduleFactory;
70     }
71
72     @Nullable
73     public ModuleInternalInfo getOldInternalInfo() {
74         if (maybeOldInternalInfo == null) {
75             throw new NullPointerException();
76         }
77         return maybeOldInternalInfo;
78     }
79
80     public TransactionModuleJMXRegistration getTransactionModuleJMXRegistration() {
81         return transactionModuleJMXRegistration;
82     }
83
84     @Override
85     public ModuleIdentifier getIdentifier() {
86         return name;
87     }
88
89     public boolean isDefaultBean() {
90         return isDefaultBean;
91     }
92
93     public Module getRealModule() {
94         return realModule;
95     }
96
97     public BundleContext getBundleContext() {
98         return bundleContext;
99     }
100 }