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;
11 import org.opendaylight.controller.config.api.ModuleIdentifier;
12 import org.opendaylight.controller.config.manager.impl.dependencyresolver.DestroyedModule;
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.controller.config.spi.ModuleFactory;
18 import org.opendaylight.yangtools.concepts.Identifiable;
19 import org.osgi.framework.BundleContext;
22 * Provides metadata about Module from controller to registry.
24 public class ModuleInternalInfo implements Comparable<ModuleInternalInfo>,
25 Identifiable<ModuleIdentifier>{
27 private final ModuleIdentifier name;
28 // this registrator is passed to runtime bean registrator and config
29 // registry to register read only module.
30 // writable modules are registered using TransactionJMXRegistrator
32 private final DynamicReadableWrapper readableModule;
34 private final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
35 // added when bean instance is registered to Osgi
36 // can be unregistered using this registration
37 private final OsgiRegistration osgiRegistration;
38 private final ModuleJMXRegistrator moduleJMXRegistrator;
39 private final int orderingIdx;
40 private final boolean isDefaultBean;
41 private final ModuleFactory moduleFactory;
42 private final BundleContext bundleContext;
44 public ModuleInternalInfo(ModuleIdentifier name,
45 @Nullable DynamicReadableWrapper readableModule,
46 OsgiRegistration osgiRegistration,
47 @Nullable RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
48 ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx,
49 boolean isDefaultBean, ModuleFactory moduleFactory, BundleContext bundleContext) {
51 if (osgiRegistration == null) {
52 throw new IllegalArgumentException(
53 "Parameter 'osgiRegistration' is missing");
55 this.readableModule = readableModule;
56 this.osgiRegistration = osgiRegistration;
57 this.runtimeBeanRegistrator = runtimeBeanRegistrator;
59 this.moduleJMXRegistrator = moduleJMXRegistrator;
60 this.orderingIdx = orderingIdx;
61 this.isDefaultBean = isDefaultBean;
62 this.moduleFactory = moduleFactory;
63 this.bundleContext = bundleContext;
66 public DynamicReadableWrapper getReadableModule() {
67 return readableModule;
70 public ModuleJMXRegistrator getModuleJMXRegistrator() {
71 return moduleJMXRegistrator;
76 * @return iif an running instance exists in the system.
78 public boolean hasReadableModule() {
79 return readableModule != null;
83 public String toString() {
84 return "ModuleInternalInfo [name=" + name + "]";
87 public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
88 return runtimeBeanRegistrator;
91 public OsgiRegistration getOsgiRegistration() {
92 return osgiRegistration;
96 * Get index representing dependency ordering within a transaction.
98 public int getOrderingIdx() {
103 * Compare using orderingIdx
106 public int compareTo(ModuleInternalInfo o) {
107 return Integer.compare(orderingIdx, o.orderingIdx);
110 public DestroyedModule toDestroyedModule() {
111 return new DestroyedModule(getIdentifier(),
112 getReadableModule().getInstance(), getModuleJMXRegistrator(),
113 getOsgiRegistration(), getOrderingIdx(), runtimeBeanRegistrator);
117 public ModuleIdentifier getIdentifier() {
121 public boolean isDefaultBean() {
122 return isDefaultBean;
125 public ModuleFactory getModuleFactory() {
126 return moduleFactory;
129 public BundleContext getBundleContext() {
130 return bundleContext;