Merge "Remove raw references to Map in XSQL"
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / ModuleInternalInfo.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;
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>,
25                 Identifiable<ModuleIdentifier>{
26
27     private final ModuleIdentifier name;
28     // this registrator is passed to runtime bean registrator and config
29     // registry to register read only module.
30     // writable modules are registered using TransactionJMXRegistrator
31     @Nullable
32     private final DynamicReadableWrapper readableModule;
33
34     private final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
35     // added when bean instance is registered to Osgi
36     // can be unregistered using this registration
37     private final OsgiRegistration osgiRegistration;
38     private final ModuleJMXRegistrator moduleJMXRegistrator;
39     private final int orderingIdx;
40     private final boolean isDefaultBean;
41     private final ModuleFactory moduleFactory;
42     private final BundleContext bundleContext;
43
44     public ModuleInternalInfo(ModuleIdentifier name,
45             @Nullable DynamicReadableWrapper readableModule,
46             OsgiRegistration osgiRegistration,
47             RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
48             ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx,
49             boolean isDefaultBean, ModuleFactory moduleFactory, BundleContext bundleContext) {
50
51         if (osgiRegistration == null) {
52             throw new IllegalArgumentException(
53                     "Parameter 'osgiRegistration' is missing");
54         }
55         if (runtimeBeanRegistrator == null) {
56             throw new IllegalArgumentException(
57                     "Parameter 'runtimeBeanRegistrator' is missing");
58         }
59         this.readableModule = readableModule;
60         this.osgiRegistration = osgiRegistration;
61         this.runtimeBeanRegistrator = runtimeBeanRegistrator;
62         this.name = name;
63         this.moduleJMXRegistrator = moduleJMXRegistrator;
64         this.orderingIdx = orderingIdx;
65         this.isDefaultBean = isDefaultBean;
66         this.moduleFactory = moduleFactory;
67         this.bundleContext = bundleContext;
68     }
69
70     public DynamicReadableWrapper getReadableModule() {
71         return readableModule;
72     }
73
74     public ModuleJMXRegistrator getModuleJMXRegistrator() {
75         return moduleJMXRegistrator;
76     }
77
78     /**
79      *
80      * @return iif an running instance exists in the system.
81      */
82     public boolean hasReadableModule() {
83         return readableModule != null;
84     }
85
86     @Override
87     public String toString() {
88         return "ModuleInternalInfo [name=" + name + "]";
89     }
90
91     public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
92         return runtimeBeanRegistrator;
93     }
94
95     public OsgiRegistration getOsgiRegistration() {
96         return osgiRegistration;
97     }
98
99     /**
100      * Get index representing dependency ordering within a transaction.
101      */
102     public int getOrderingIdx() {
103         return orderingIdx;
104     }
105
106     /**
107      * Compare using orderingIdx
108      */
109     @Override
110     public int compareTo(ModuleInternalInfo o) {
111         return Integer.compare(orderingIdx, o.orderingIdx);
112     }
113
114     public DestroyedModule toDestroyedModule() {
115         return new DestroyedModule(getIdentifier(),
116                 getReadableModule().getInstance(), getModuleJMXRegistrator(),
117                 getOsgiRegistration(), getOrderingIdx());
118     }
119
120     @Override
121     public ModuleIdentifier getIdentifier() {
122         return name;
123     }
124
125     public boolean isDefaultBean() {
126         return isDefaultBean;
127     }
128
129     public ModuleFactory getModuleFactory() {
130         return moduleFactory;
131     }
132
133     public BundleContext getBundleContext() {
134         return bundleContext;
135     }
136 }