2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.manager.impl;
10 import javax.annotation.Nullable;
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.controller.config.spi.ModuleFactory;
19 import org.opendaylight.yangtools.concepts.Identifiable;
20 import org.osgi.framework.BundleContext;
23 * Provides metadata about Module from controller to registry.
25 public class ModuleInternalInfo implements Comparable<ModuleInternalInfo>,
26 Identifiable<ModuleIdentifier>{
28 private final ModuleIdentifier name;
29 // this registrator is passed to runtime bean registrator and config
30 // registry to register read only module.
31 // writable modules are registered using TransactionJMXRegistrator
33 private final DynamicReadableWrapper readableModule;
35 private final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
36 // added when bean instance is registered to Osgi
37 // can be unregistered using this registration
38 private final OsgiRegistration osgiRegistration;
39 private final ModuleJMXRegistrator moduleJMXRegistrator;
40 private final int orderingIdx;
41 private final boolean isDefaultBean;
42 private final ModuleFactory moduleFactory;
43 private final BundleContext bundleContext;
45 public ModuleInternalInfo(ModuleIdentifier name,
46 @Nullable DynamicReadableWrapper readableModule,
47 OsgiRegistration osgiRegistration,
48 RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
49 ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx,
50 boolean isDefaultBean, ModuleFactory moduleFactory, BundleContext bundleContext) {
52 if (osgiRegistration == null) {
53 throw new IllegalArgumentException(
54 "Parameter 'osgiRegistration' is missing");
56 if (runtimeBeanRegistrator == null) {
57 throw new IllegalArgumentException(
58 "Parameter 'runtimeBeanRegistrator' is missing");
60 this.readableModule = readableModule;
61 this.osgiRegistration = osgiRegistration;
62 this.runtimeBeanRegistrator = runtimeBeanRegistrator;
64 this.moduleJMXRegistrator = moduleJMXRegistrator;
65 this.orderingIdx = orderingIdx;
66 this.isDefaultBean = isDefaultBean;
67 this.moduleFactory = moduleFactory;
68 this.bundleContext = bundleContext;
71 public DynamicReadableWrapper getReadableModule() {
72 return readableModule;
75 public ModuleJMXRegistrator getModuleJMXRegistrator() {
76 return moduleJMXRegistrator;
81 * @return iif an running instance exists in the system.
83 public boolean hasReadableModule() {
84 return readableModule != null;
88 public String toString() {
89 return "ModuleInternalInfo [name=" + name + "]";
92 public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
93 return runtimeBeanRegistrator;
96 public OsgiRegistration getOsgiRegistration() {
97 return osgiRegistration;
101 * Get index representing dependency ordering within a transaction.
103 public int getOrderingIdx() {
108 * Compare using orderingIdx
111 public int compareTo(ModuleInternalInfo o) {
112 return Integer.compare(orderingIdx, o.orderingIdx);
115 public DestroyedModule toDestroyedModule() {
116 return new DestroyedModule(getIdentifier(),
117 getReadableModule().getInstance(), getModuleJMXRegistrator(),
118 getOsgiRegistration(), getOrderingIdx());
122 public ModuleIdentifier getIdentifier() {
126 public boolean isDefaultBean() {
127 return isDefaultBean;
130 public ModuleFactory getModuleFactory() {
131 return moduleFactory;
134 public BundleContext getBundleContext() {
135 return bundleContext;