Merge "Increase timeout for waiting for broker service in sal-binding-it."
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / RuntimeMappingModuleFactory.java
1 /*
2  * Copyright (c) 2014 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.yang.md.sal.binding.impl;
9
10 import java.util.Collections;
11 import java.util.Set;
12
13 import org.opendaylight.controller.config.api.DependencyResolver;
14 import org.opendaylight.controller.config.api.DependencyResolverFactory;
15 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
16 import org.opendaylight.controller.config.api.ModuleIdentifier;
17 import org.opendaylight.controller.config.spi.Module;
18 import org.osgi.framework.BundleContext;
19
20 /**
21 *
22 */
23 public class RuntimeMappingModuleFactory extends
24         org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractRuntimeMappingModuleFactory {
25
26     private static RuntimeMappingModule SINGLETON = null;
27     private static ModuleIdentifier IDENTIFIER = new ModuleIdentifier(NAME, "runtime-mapping-singleton");
28
29     @Override
30     public Module createModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) {
31         throw new UnsupportedOperationException("Only default instance supported");
32     }
33
34     @Override
35     public Module createModule(String instanceName, DependencyResolver dependencyResolver,
36             DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception {
37         RuntimeMappingModule module = (RuntimeMappingModule) super.createModule(instanceName, dependencyResolver, old,
38                 bundleContext);
39         module.setBundleContext(bundleContext);
40         return module;
41     }
42
43     @Override
44     public Set<RuntimeMappingModule> getDefaultModules(DependencyResolverFactory dependencyResolverFactory,
45             BundleContext bundleContext) {
46         if (SINGLETON == null) {
47             DependencyResolver dependencyResolver = dependencyResolverFactory.createDependencyResolver(IDENTIFIER);
48             SINGLETON = new RuntimeMappingModule(IDENTIFIER, dependencyResolver);
49             SINGLETON.setBundleContext(bundleContext);
50         }
51
52         return Collections.singleton(SINGLETON);
53     }
54
55 }