Fixed typo in SnapshotBackedWriteTransaction class
[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.dependencyresolver.DestroyedModule;
14 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
15 import org.opendaylight.controller.config.manager.impl.jmx.ModuleJMXRegistrator;
16 import org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl;
17 import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager.OsgiRegistration;
18 import org.opendaylight.yangtools.concepts.Identifiable;
19
20 /**
21  * Provides metadata about Module from controller to registry.
22  */
23 public class ModuleInternalInfo implements Comparable<ModuleInternalInfo>,
24                 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
41     public ModuleInternalInfo(ModuleIdentifier name,
42             @Nullable DynamicReadableWrapper readableModule,
43             OsgiRegistration osgiRegistration,
44             RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
45             ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx,
46             boolean isDefaultBean) {
47
48         if (osgiRegistration == null) {
49             throw new IllegalArgumentException(
50                     "Parameter 'osgiRegistration' is missing");
51         }
52         if (runtimeBeanRegistrator == null) {
53             throw new IllegalArgumentException(
54                     "Parameter 'runtimeBeanRegistrator' is missing");
55         }
56         this.readableModule = readableModule;
57         this.osgiRegistration = osgiRegistration;
58         this.runtimeBeanRegistrator = runtimeBeanRegistrator;
59         this.name = name;
60         this.moduleJMXRegistrator = moduleJMXRegistrator;
61         this.orderingIdx = orderingIdx;
62         this.isDefaultBean = isDefaultBean;
63     }
64
65     public DynamicReadableWrapper getReadableModule() {
66         return readableModule;
67     }
68
69     public ModuleJMXRegistrator getModuleJMXRegistrator() {
70         return moduleJMXRegistrator;
71     }
72
73     /**
74      *
75      * @return iif an running instance exists in the system.
76      */
77     public boolean hasReadableModule() {
78         return readableModule != null;
79     }
80
81     @Override
82     public String toString() {
83         return "ModuleInternalInfo [name=" + name + "]";
84     }
85
86     public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
87         return runtimeBeanRegistrator;
88     }
89
90     public OsgiRegistration getOsgiRegistration() {
91         return osgiRegistration;
92     }
93
94     /**
95      * Get index representing dependency ordering within a transaction.
96      */
97     public int getOrderingIdx() {
98         return orderingIdx;
99     }
100
101     /**
102      * Compare using orderingIdx
103      */
104     @Override
105     public int compareTo(ModuleInternalInfo o) {
106         return Integer.compare(orderingIdx, o.orderingIdx);
107     }
108
109     public DestroyedModule toDestroyedModule() {
110         return new DestroyedModule(getIdentifier(),
111                 getReadableModule().getInstance(), getModuleJMXRegistrator(),
112                 getOsgiRegistration(), getOrderingIdx());
113     }
114
115     @Override
116     public ModuleIdentifier getIdentifier() {
117         return name;
118     }
119
120     public boolean isDefaultBean() {
121         return isDefaultBean;
122     }
123 }