config-manager: final parameters
[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(final ModuleIdentifier name,
45             @Nullable final DynamicReadableWrapper readableModule,
46             final OsgiRegistration osgiRegistration,
47             @Nullable final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
48             final ModuleJMXRegistrator moduleJMXRegistrator, final int orderingIdx,
49             final boolean isDefaultBean, final ModuleFactory moduleFactory, final BundleContext bundleContext) {
50
51         if (osgiRegistration == null) {
52             throw new IllegalArgumentException(
53                     "Parameter 'osgiRegistration' is missing");
54         }
55         this.readableModule = readableModule;
56         this.osgiRegistration = osgiRegistration;
57         this.runtimeBeanRegistrator = runtimeBeanRegistrator;
58         this.name = name;
59         this.moduleJMXRegistrator = moduleJMXRegistrator;
60         this.orderingIdx = orderingIdx;
61         this.isDefaultBean = isDefaultBean;
62         this.moduleFactory = moduleFactory;
63         this.bundleContext = bundleContext;
64     }
65
66     public DynamicReadableWrapper getReadableModule() {
67         return readableModule;
68     }
69
70     public ModuleJMXRegistrator getModuleJMXRegistrator() {
71         return moduleJMXRegistrator;
72     }
73
74     /**
75      *
76      * @return iif an running instance exists in the system.
77      */
78     public boolean hasReadableModule() {
79         return readableModule != null;
80     }
81
82     @Override
83     public String toString() {
84         return "ModuleInternalInfo [name=" + name + "]";
85     }
86
87     public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
88         return runtimeBeanRegistrator;
89     }
90
91     public OsgiRegistration getOsgiRegistration() {
92         return osgiRegistration;
93     }
94
95     /**
96      * Get index representing dependency ordering within a transaction.
97      */
98     public int getOrderingIdx() {
99         return orderingIdx;
100     }
101
102     /**
103      * Compare using orderingIdx
104      */
105     @Override
106     public int compareTo(final ModuleInternalInfo o) {
107         return Integer.compare(orderingIdx, o.orderingIdx);
108     }
109
110     public DestroyedModule toDestroyedModule() {
111         return new DestroyedModule(getIdentifier(),
112                 getReadableModule().getInstance(), getModuleJMXRegistrator(),
113                 getOsgiRegistration(), getOrderingIdx(), runtimeBeanRegistrator);
114     }
115
116     @Override
117     public ModuleIdentifier getIdentifier() {
118         return name;
119     }
120
121     public boolean isDefaultBean() {
122         return isDefaultBean;
123     }
124
125     public ModuleFactory getModuleFactory() {
126         return moduleFactory;
127     }
128
129     public BundleContext getBundleContext() {
130         return bundleContext;
131     }
132 }