added implementation of Identifier and Identifiable from yangtools.concepts
[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
39     public ModuleInternalInfo(ModuleIdentifier name,
40             @Nullable DynamicReadableWrapper readableModule,
41             OsgiRegistration osgiRegistration,
42             RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
43             ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx) {
44
45         if (osgiRegistration == null) {
46             throw new IllegalArgumentException(
47                     "Parameter 'osgiRegistration' is missing");
48         }
49         if (runtimeBeanRegistrator == null) {
50             throw new IllegalArgumentException(
51                     "Parameter 'runtimeBeanRegistrator' is missing");
52         }
53         this.readableModule = readableModule;
54         this.osgiRegistration = osgiRegistration;
55         this.runtimeBeanRegistrator = runtimeBeanRegistrator;
56         this.name = name;
57         this.moduleJMXRegistrator = moduleJMXRegistrator;
58         this.orderingIdx = orderingIdx;
59     }
60
61     public DynamicReadableWrapper getReadableModule() {
62         return readableModule;
63     }
64
65     public ModuleJMXRegistrator getModuleJMXRegistrator() {
66         return moduleJMXRegistrator;
67     }
68
69     /**
70      *
71      * @return iif an running instance exists in the system.
72      */
73     public boolean hasReadableModule() {
74         return readableModule != null;
75     }
76
77     @Override
78     public String toString() {
79         return "ModuleInternalInfo [name=" + name + "]";
80     }
81
82     public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
83         return runtimeBeanRegistrator;
84     }
85
86     public OsgiRegistration getOsgiRegistration() {
87         return osgiRegistration;
88     }
89
90     @Deprecated
91     public ModuleIdentifier getName() {
92         return name;
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(ModuleInternalInfo o) {
107         return Integer.compare(orderingIdx, o.orderingIdx);
108     }
109
110     public DestroyedModule toDestroyedModule() {
111         return new DestroyedModule(getName(),
112                 getReadableModule().getInstance(), getModuleJMXRegistrator(),
113                 getOsgiRegistration(), getOrderingIdx());
114     }
115
116     @Override
117     public ModuleIdentifier getIdentifier() {
118         return name;
119     }
120 }