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