Fix checkstyle issues to enforce it
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / ModuleInternalInfo.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;
9
10 import javax.annotation.Nullable;
11 import org.opendaylight.controller.config.api.ModuleIdentifier;
12 import org.opendaylight.controller.config.manager.impl.dependencyresolver.DestroyedModule;
13 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
14 import org.opendaylight.controller.config.manager.impl.jmx.ModuleJMXRegistrator;
15 import org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl;
16 import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager.OsgiRegistration;
17 import org.opendaylight.controller.config.spi.ModuleFactory;
18 import org.opendaylight.yangtools.concepts.Identifiable;
19 import org.osgi.framework.BundleContext;
20
21 /**
22  * Provides metadata about Module from controller to registry.
23  */
24 public class ModuleInternalInfo implements Comparable<ModuleInternalInfo>, Identifiable<ModuleIdentifier> {
25
26     private final ModuleIdentifier name;
27     // this registrator is passed to runtime bean registrator and config
28     // registry to register read only module.
29     // writable modules are registered using TransactionJMXRegistrator
30     @Nullable
31     private final DynamicReadableWrapper readableModule;
32
33     private final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
34     // added when bean instance is registered to Osgi
35     // can be unregistered using this registration
36     private final OsgiRegistration osgiRegistration;
37     private final ModuleJMXRegistrator moduleJMXRegistrator;
38     private final int orderingIdx;
39     private final boolean isDefaultBean;
40     private final ModuleFactory moduleFactory;
41     private final BundleContext bundleContext;
42
43     public ModuleInternalInfo(final ModuleIdentifier name, @Nullable final DynamicReadableWrapper readableModule,
44             final OsgiRegistration osgiRegistration,
45             @Nullable final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
46             final ModuleJMXRegistrator moduleJMXRegistrator, final int orderingIdx, final boolean isDefaultBean,
47             final ModuleFactory moduleFactory, final BundleContext bundleContext) {
48
49         if (osgiRegistration == null) {
50             throw new IllegalArgumentException("Parameter 'osgiRegistration' is missing");
51         }
52         this.readableModule = readableModule;
53         this.osgiRegistration = osgiRegistration;
54         this.runtimeBeanRegistrator = runtimeBeanRegistrator;
55         this.name = name;
56         this.moduleJMXRegistrator = moduleJMXRegistrator;
57         this.orderingIdx = orderingIdx;
58         this.isDefaultBean = isDefaultBean;
59         this.moduleFactory = moduleFactory;
60         this.bundleContext = bundleContext;
61     }
62
63     public DynamicReadableWrapper getReadableModule() {
64         return readableModule;
65     }
66
67     public ModuleJMXRegistrator getModuleJMXRegistrator() {
68         return moduleJMXRegistrator;
69     }
70
71     /**
72      * Tells if a running instance exists in the system.
73      *
74      * @return is there any running instance in the system.
75      */
76     public boolean hasReadableModule() {
77         return readableModule != null;
78     }
79
80     @Override
81     public String toString() {
82         return "ModuleInternalInfo [name=" + name + "]";
83     }
84
85     public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
86         return runtimeBeanRegistrator;
87     }
88
89     public OsgiRegistration getOsgiRegistration() {
90         return osgiRegistration;
91     }
92
93     /**
94      * Get index representing dependency ordering within a transaction.
95      *
96      * @return index
97      */
98     public int getOrderingIdx() {
99         return orderingIdx;
100     }
101
102     @Override
103     public int compareTo(final ModuleInternalInfo moduleInternalInfo) {
104         return Integer.compare(orderingIdx, moduleInternalInfo.orderingIdx);
105     }
106
107     public DestroyedModule toDestroyedModule() {
108         return new DestroyedModule(getIdentifier(), getReadableModule().getInstance(), getModuleJMXRegistrator(),
109                 getOsgiRegistration(), getOrderingIdx(), runtimeBeanRegistrator);
110     }
111
112     @Override
113     public ModuleIdentifier getIdentifier() {
114         return name;
115     }
116
117     public boolean isDefaultBean() {
118         return isDefaultBean;
119     }
120
121     public ModuleFactory getModuleFactory() {
122         return moduleFactory;
123     }
124
125     public BundleContext getBundleContext() {
126         return bundleContext;
127     }
128 }