2 * Copyright (c) 2013, 2017 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>, Identifiable<ModuleIdentifier> {
26 private final ModuleIdentifier name;
27 // this registrator is passed to runtime bean registrator and config
28 // registry to register read only module.
29 // writable modules are registered using TransactionJMXRegistrator
31 private final DynamicReadableWrapper readableModule;
33 private final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
34 // added when bean instance is registered to Osgi
35 // can be unregistered using this registration
36 private final OsgiRegistration osgiRegistration;
37 private final ModuleJMXRegistrator moduleJMXRegistrator;
38 private final int orderingIdx;
39 private final boolean isDefaultBean;
40 private final ModuleFactory moduleFactory;
41 private final BundleContext bundleContext;
43 public ModuleInternalInfo(final ModuleIdentifier name, @Nullable final DynamicReadableWrapper readableModule,
44 final OsgiRegistration osgiRegistration,
45 @Nullable final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
46 final ModuleJMXRegistrator moduleJMXRegistrator, final int orderingIdx, final boolean isDefaultBean,
47 final ModuleFactory moduleFactory, final BundleContext bundleContext) {
49 if (osgiRegistration == null) {
50 throw new IllegalArgumentException("Parameter 'osgiRegistration' is missing");
52 this.readableModule = readableModule;
53 this.osgiRegistration = osgiRegistration;
54 this.runtimeBeanRegistrator = runtimeBeanRegistrator;
56 this.moduleJMXRegistrator = moduleJMXRegistrator;
57 this.orderingIdx = orderingIdx;
58 this.isDefaultBean = isDefaultBean;
59 this.moduleFactory = moduleFactory;
60 this.bundleContext = bundleContext;
63 public DynamicReadableWrapper getReadableModule() {
64 return readableModule;
67 public ModuleJMXRegistrator getModuleJMXRegistrator() {
68 return moduleJMXRegistrator;
72 * Tells if a running instance exists in the system.
74 * @return is there any running instance in the system.
76 public boolean hasReadableModule() {
77 return readableModule != null;
81 public String toString() {
82 return "ModuleInternalInfo [name=" + name + "]";
85 public RootRuntimeBeanRegistratorImpl getRuntimeBeanRegistrator() {
86 return runtimeBeanRegistrator;
89 public OsgiRegistration getOsgiRegistration() {
90 return osgiRegistration;
94 * Get index representing dependency ordering within a transaction.
98 public int getOrderingIdx() {
103 public int compareTo(final ModuleInternalInfo moduleInternalInfo) {
104 return Integer.compare(orderingIdx, moduleInternalInfo.orderingIdx);
107 public DestroyedModule toDestroyedModule() {
108 return new DestroyedModule(getIdentifier(), getReadableModule().getInstance(), getModuleJMXRegistrator(),
109 getOsgiRegistration(), getOrderingIdx(), runtimeBeanRegistrator);
113 public ModuleIdentifier getIdentifier() {
117 public boolean isDefaultBean() {
118 return isDefaultBean;
121 public ModuleFactory getModuleFactory() {
122 return moduleFactory;
125 public BundleContext getBundleContext() {
126 return bundleContext;