Added reuse support to MD-SAL for config subsystem
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / BindingBrokerImplSingletonModuleFactory.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
9 package org.opendaylight.controller.config.yang.md.sal.binding.impl;
10
11 import java.util.Collections;
12 import java.util.Set;
13
14 import org.opendaylight.controller.config.api.DependencyResolver;
15 import org.opendaylight.controller.config.api.DependencyResolverFactory;
16 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
17 import org.opendaylight.controller.config.api.ModuleIdentifier;
18 import org.opendaylight.controller.config.spi.Module;
19 import org.osgi.framework.BundleContext;
20
21 /**
22 *
23 */
24 public class BindingBrokerImplSingletonModuleFactory extends
25         org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractBindingBrokerImplSingletonModuleFactory {
26
27     private static final String SINGLETON_NAME = "binding-broker-singleton";
28     public static BindingBrokerImplSingletonModule SINGLETON;
29     public static ModuleIdentifier SINGLETON_IDENTIFIER = new ModuleIdentifier(NAME, SINGLETON_NAME);
30
31     @Override
32     public Module createModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) {
33         throw new UnsupportedOperationException("Only default instance supported.");
34     }
35     
36     @Override
37     public Module createModule(String instanceName, DependencyResolver dependencyResolver,
38             DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception {
39         return SINGLETON;
40     }
41
42     @Override
43     public Set<BindingBrokerImplSingletonModule> getDefaultModules(DependencyResolverFactory dependencyResolverFactory,
44             BundleContext bundleContext) {
45             if (SINGLETON == null) {
46
47                 DependencyResolver dependencyResolver = dependencyResolverFactory
48                         .createDependencyResolver(SINGLETON_IDENTIFIER);
49                 SINGLETON = new BindingBrokerImplSingletonModule(SINGLETON_IDENTIFIER, dependencyResolver);
50                 SINGLETON.setBundleContext(bundleContext);
51             }
52
53             return Collections.singleton(SINGLETON);
54     }
55
56 }