Merge "Add numberOfBackups=1 property to config.ini's netconf.config.persister.2...
[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
12 import org.opendaylight.controller.config.api.ModuleIdentifier;
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.yangtools.concepts.Identifiable;
18
19 /**
20  * Provides metadata about Module from controller to registry.
21  */
22 public class ModuleInternalInfo implements Comparable<ModuleInternalInfo>,
23                 Identifiable<ModuleIdentifier>{
24
25     private final ModuleIdentifier name;
26     // this registrator is passed to runtime bean registrator and config
27     // registry to register read only module.
28     // writable modules are registered using TransactionJMXRegistrator
29     @Nullable
30     private final DynamicReadableWrapper readableModule;
31
32     private final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
33     // added when bean instance is registered to Osgi
34     // can be unregistered using this registration
35     private final OsgiRegistration osgiRegistration;
36     private final ModuleJMXRegistrator moduleJMXRegistrator;
37     private final int orderingIdx;
38     private final boolean isDefaultBean;
39
40     public ModuleInternalInfo(ModuleIdentifier name,
41             @Nullable DynamicReadableWrapper readableModule,
42             OsgiRegistration osgiRegistration,
43             RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
44             ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx,
45             boolean isDefaultBean) {
46
47         if (osgiRegistration == null) {
48             throw new IllegalArgumentException(
49                     "Parameter 'osgiRegistration' is missing");
50         }
51         if (runtimeBeanRegistrator == null) {
52             throw new IllegalArgumentException(
53                     "Parameter 'runtimeBeanRegistrator' 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     }
63
64     public DynamicReadableWrapper getReadableModule() {
65         return readableModule;
66     }
67
68     public ModuleJMXRegistrator getModuleJMXRegistrator() {
69         return moduleJMXRegistrator;
70     }
71
72     /**
73      *
74      * @return iif an running instance exists 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     @Deprecated
94     public ModuleIdentifier getName() {
95         return name;
96     }
97
98     /**
99      * Get index representing dependency ordering within a transaction.
100      */
101     public int getOrderingIdx() {
102         return orderingIdx;
103     }
104
105     /**
106      * Compare using orderingIdx
107      */
108     @Override
109     public int compareTo(ModuleInternalInfo o) {
110         return Integer.compare(orderingIdx, o.orderingIdx);
111     }
112
113     public DestroyedModule toDestroyedModule() {
114         return new DestroyedModule(getName(),
115                 getReadableModule().getInstance(), getModuleJMXRegistrator(),
116                 getOsgiRegistration(), getOrderingIdx());
117     }
118
119     @Override
120     public ModuleIdentifier getIdentifier() {
121         return name;
122     }
123
124     public boolean isDefaultBean() {
125         return isDefaultBean;
126     }
127 }