bump netty to version 4.0.10.Final
[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
18 /**
19  * Provides metadata about Module from controller to registry.
20  */
21 public class ModuleInternalInfo implements Comparable<ModuleInternalInfo> {
22
23     private final ModuleIdentifier name;
24     // this registrator is passed to runtime bean registrator and config
25     // registry to register read only module.
26     // writable modules are registered using TransactionJMXRegistrator
27     @Nullable
28     private final DynamicReadableWrapper readableModule;
29
30     private final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
31     // added when bean instance is registered to Osgi
32     // can be unregistered using this registration
33     private final OsgiRegistration osgiRegistration;
34     private final ModuleJMXRegistrator moduleJMXRegistrator;
35     private final int orderingIdx;
36
37     public ModuleInternalInfo(ModuleIdentifier name,
38             @Nullable DynamicReadableWrapper readableModule,
39             OsgiRegistration osgiRegistration,
40             RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
41             ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx) {
42
43         if (osgiRegistration == null) {
44             throw new IllegalArgumentException(
45                     "Parameter 'osgiRegistration' is missing");
46         }
47         if (runtimeBeanRegistrator == null) {
48             throw new IllegalArgumentException(
49                     "Parameter 'runtimeBeanRegistrator' is missing");
50         }
51         this.readableModule = readableModule;
52         this.osgiRegistration = osgiRegistration;
53         this.runtimeBeanRegistrator = runtimeBeanRegistrator;
54         this.name = name;
55         this.moduleJMXRegistrator = moduleJMXRegistrator;
56         this.orderingIdx = orderingIdx;
57     }
58
59     public DynamicReadableWrapper getReadableModule() {
60         return readableModule;
61     }
62
63     public ModuleJMXRegistrator getModuleJMXRegistrator() {
64         return moduleJMXRegistrator;
65     }
66
67     /**
68      *
69      * @return iif an running instance exists in the system.
70      */
71     public boolean hasReadableModule() {
72         return readableModule != null;
73     }
74
75     @Override
76     public String toString() {
77         return "ModuleInternalInfo [name=" + name + "]";
78     }
79
80     public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
81         return runtimeBeanRegistrator;
82     }
83
84     public OsgiRegistration getOsgiRegistration() {
85         return osgiRegistration;
86     }
87
88     public ModuleIdentifier getName() {
89         return name;
90     }
91
92     /**
93      * Get index representing dependency ordering within a transaction.
94      */
95     public int getOrderingIdx() {
96         return orderingIdx;
97     }
98
99     /**
100      * Compare using orderingIdx
101      */
102     @Override
103     public int compareTo(ModuleInternalInfo o) {
104         return Integer.compare(orderingIdx, o.orderingIdx);
105     }
106
107     public DestroyedModule toDestroyedModule() {
108         return new DestroyedModule(getName(),
109                 getReadableModule().getInstance(), getModuleJMXRegistrator(),
110                 getOsgiRegistration(), getOrderingIdx());
111     }
112 }