Add service reference binding to config registry.
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / parallelapsp / TestingParallelAPSPModuleFactory.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.manager.testingservices.parallelapsp;
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.ModuleIdentifier;
14 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
15 import org.opendaylight.controller.config.spi.Module;
16 import org.opendaylight.controller.config.spi.ModuleFactory;
17 import org.osgi.framework.BundleContext;
18
19 import javax.annotation.concurrent.ThreadSafe;
20 import javax.management.ObjectName;
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.Set;
24
25 @ThreadSafe
26 public class TestingParallelAPSPModuleFactory implements ModuleFactory {
27
28     public static final String NAME = "parallel";
29
30     @Override
31     public String getImplementationName() {
32         return NAME;
33     }
34
35     @Override
36     public TestingParallelAPSPModule createModule(String instanceName,
37             DependencyResolver dependencyResolver, BundleContext bundleContext) {
38         return new TestingParallelAPSPModule(new ModuleIdentifier(NAME,
39                 instanceName), dependencyResolver, null, null);
40     }
41
42     @Override
43     public TestingParallelAPSPModule createModule(String instanceName,
44             DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext context)
45             throws Exception {
46         TestingParallelAPSPImpl oldInstance;
47         try {
48             oldInstance = (TestingParallelAPSPImpl) old.getInstance();
49         } catch (ClassCastException e) {
50             oldInstance = null;
51         }
52         TestingParallelAPSPModule result = new TestingParallelAPSPModule(
53                 new ModuleIdentifier(NAME, instanceName), dependencyResolver,
54                 old.getInstance(), oldInstance);
55         // copy attributes
56         String someParam = (String) old.getAttribute("SomeParam");
57         result.setSomeParam(someParam);
58         ObjectName threadPool = (ObjectName) old.getAttribute("ThreadPool");
59         result.setThreadPool(threadPool);
60         return result;
61     }
62
63     @Override
64     public boolean isModuleImplementingServiceInterface(
65             Class<? extends AbstractServiceInterface> serviceInterface) {
66         return false;
67     }
68
69     @Override
70     public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext context) {
71         return new HashSet<Module>();
72     }
73
74     @Override
75     public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {
76         return Collections.emptySet();
77     }
78 }