Persist service references as separate MBeans.
[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     /**
94      * Get index representing dependency ordering within a transaction.
95      */
96     public int getOrderingIdx() {
97         return orderingIdx;
98     }
99
100     /**
101      * Compare using orderingIdx
102      */
103     @Override
104     public int compareTo(ModuleInternalInfo o) {
105         return Integer.compare(orderingIdx, o.orderingIdx);
106     }
107
108     public DestroyedModule toDestroyedModule() {
109         return new DestroyedModule(getIdentifier(),
110                 getReadableModule().getInstance(), getModuleJMXRegistrator(),
111                 getOsgiRegistration(), getOrderingIdx());
112     }
113
114     @Override
115     public ModuleIdentifier getIdentifier() {
116         return name;
117     }
118
119     public boolean isDefaultBean() {
120         return isDefaultBean;
121     }
122 }