Fix checkstyle issues to enforce it
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / dependencyresolver / ModuleInternalTransactionalInfo.java
1 /*
2  * Copyright (c) 2013, 2017 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 com.google.common.base.Preconditions;
11 import javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import org.opendaylight.controller.config.api.ModuleIdentifier;
14 import org.opendaylight.controller.config.manager.impl.ModuleInternalInfo;
15 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
16 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration;
17 import org.opendaylight.controller.config.spi.Module;
18 import org.opendaylight.controller.config.spi.ModuleFactory;
19 import org.opendaylight.yangtools.concepts.Identifiable;
20 import org.osgi.framework.BundleContext;
21
22 public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdentifier> {
23     private final ModuleIdentifier name;
24     private final Module proxiedModule;
25     private final Module realModule;
26     private final ModuleFactory moduleFactory;
27
28     private final TransactionModuleJMXRegistration transactionModuleJMXRegistration;
29     private final boolean isDefaultBean;
30     private final BundleContext bundleContext;
31     @Nullable private ModuleInternalInfo maybeOldInternalInfo;
32
33     public ModuleInternalTransactionalInfo(final ModuleIdentifier name, final Module proxiedModule,
34                                            final ModuleFactory moduleFactory,
35                                            final ModuleInternalInfo maybeOldInternalInfo,
36                                            final TransactionModuleJMXRegistration transactionModuleJMXRegistration,
37                                            final boolean isDefaultBean,
38                                            final Module realModule,
39                                            final BundleContext bundleContext) {
40         this.name = name;
41         this.proxiedModule = proxiedModule;
42         this.moduleFactory = moduleFactory;
43         this.maybeOldInternalInfo = maybeOldInternalInfo;
44         this.transactionModuleJMXRegistration = transactionModuleJMXRegistration;
45         this.isDefaultBean = isDefaultBean;
46         this.realModule = realModule;
47         this.bundleContext = bundleContext;
48     }
49
50
51     public boolean hasOldModule() {
52         return maybeOldInternalInfo != null;
53     }
54
55     public DestroyedModule toDestroyedModule() {
56         if (maybeOldInternalInfo == null) {
57             throw new IllegalStateException("Cannot destroy uncommitted module");
58         }
59         DynamicReadableWrapper oldModule = maybeOldInternalInfo
60                 .getReadableModule();
61         return new DestroyedModule(name, oldModule.getInstance(),
62                 maybeOldInternalInfo.getModuleJMXRegistrator(),
63                 maybeOldInternalInfo.getOsgiRegistration(),
64                 maybeOldInternalInfo.getOrderingIdx(), maybeOldInternalInfo.getRuntimeBeanRegistrator());
65     }
66
67
68     public Module getProxiedModule() {
69         return proxiedModule;
70     }
71
72     public ModuleFactory getModuleFactory() {
73         return moduleFactory;
74     }
75
76     @Nonnull public ModuleInternalInfo getOldInternalInfo() {
77         return Preconditions.checkNotNull(maybeOldInternalInfo);
78     }
79
80     public void clearOldInternalInfo() {
81         Preconditions.checkState(maybeOldInternalInfo != null, "No old internal info present");
82         maybeOldInternalInfo = null;
83     }
84
85     public TransactionModuleJMXRegistration getTransactionModuleJMXRegistration() {
86         return transactionModuleJMXRegistration;
87     }
88
89     @Override
90     public ModuleIdentifier getIdentifier() {
91         return name;
92     }
93
94     public boolean isDefaultBean() {
95         return isDefaultBean;
96     }
97
98     public Module getRealModule() {
99         return realModule;
100     }
101
102     public BundleContext getBundleContext() {
103         return bundleContext;
104     }
105 }