Added BundleContext reference to generated factories for config subsystem
[controller.git] / opendaylight / config / config-api / src / main / java / org / opendaylight / controller / config / spi / ModuleFactory.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.spi;
9
10 import org.opendaylight.controller.config.api.DependencyResolver;
11 import org.opendaylight.controller.config.api.DependencyResolverFactory;
12 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
13 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
14 import org.osgi.framework.BundleContext;
15
16 import javax.management.DynamicMBean;
17 import java.util.Set;
18
19 /**
20  * Factory which creates {@link Module instances. An instance of this interface
21  * needs to be exported into the OSGi Service Registry. Such an instance
22  * provides metadata describing services which can be published from it.
23  *
24  * Each {@link Module } can optionally be instantiated with a
25  * {@link DynamicMBean} which represents the configuration of the currently
26  * running instance.
27  */
28 public interface ModuleFactory {
29
30     /**
31      * Returns the human-friendly implementation name. This value needs to be
32      * unique within all implementations of all interfaces returned by
33      * getImplementedInterfaces().
34      *
35      * @return human-friendly implementation name
36      */
37     public String getImplementationName();
38
39     /**
40      * Create a new Module instance. The returned object is expected to use the
41      * dependencyResolver provided when resolving ObjectNames to actual Module
42      * instances.
43      *
44      * @param dependencyResolver
45      *            This resolver will return actual config mbean based on its
46      *            ObjectName.
47      * @param bundleContext Reference to OSGi bundleContext that can be used to
48      *                      acquire OSGi services, startup configuration and other
49      *                      OSGi related information.
50      *
51      * @return newly created module
52      *
53      */
54     public Module createModule(String instanceName,
55             DependencyResolver dependencyResolver, BundleContext bundleContext);
56
57     /**
58      * Create a new Module instance. The returned object is expected to use the
59      * dependencyResolver provided when resolving ObjectNames to actual Module
60      * instances. A reference to an abstract view of the previous configuration
61      * is also provided in the form of a {@link DynamicMBean}. Implementations
62      * should use the MBeanInfo interface to understand the structure of the
63      * configuration information.
64      *
65      * Structural information impacts hot-swap operations in that in order to
66      * perform such a swap the newly loaded code needs to understand the
67      * previously-running instance configuration layout and how to map it onto
68      * itself.
69      *
70      * @param dependencyResolver
71      *            This resolver will return actual config mbean based on its
72      *            ObjectName.
73      * @param old
74      *            existing module from platform MBeanServer that is being
75      *            reconfigured. Implementations should inspect its attributes
76      *            using {@link DynamicMBean#getAttribute(String)} and set those
77      *            attributes on newly created module. If reconfiguration of live
78      *            instances is supported, this live instance can be retreived
79      *            using
80      *            {@link org.opendaylight.controller.config.api.DynamicMBeanWithInstance#getInstance()}
81      *            . It is possible that casting this old instance throws
82      *            {@link ClassCastException} when OSGi bundle is being updated.
83      *            In this case, implementation should revert to creating new
84      *            instance.
85      * @param bundleContext Reference to OSGi bundleContext that can be used to
86      *                      acquire OSGi services, startup configuration and other
87      *                      OSGi related information.
88      *
89      * @return newly created module
90      * @throws Exception
91      *             if it is not possible to recover configuration from old. This
92      *             leaves server in a running state but no configuration
93      *             transaction can be created.
94      */
95     public Module createModule(String instanceName, DependencyResolver dependencyResolver,
96             DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception;
97
98     boolean isModuleImplementingServiceInterface(
99             Class<? extends AbstractServiceInterface> serviceInterface);
100
101     /**
102      * Called when ModuleFactory is registered to config manager.
103      * Useful for populating the registry with pre-existing state. Since
104      * the method is called for each ModuleFactory separately and transaction
105      * is committed automatically, returned modules MUST be valid and commitable
106      * without any manual intervention.
107      *
108      * @param dependencyResolverFactory factory for getting dependency resolvers for each module.
109      * @param bundleContext Reference to OSGi bundleContext that can be used to
110      *                      acquire OSGi services, startup configuration and other
111      *                      OSGi related information.
112      *
113      * @return set of default modules. Null is not allowed.
114      */
115     public Set<? extends Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory,
116             BundleContext bundleContext);
117
118 }