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