c4426d18e3db0d6566c3f5b57f7beeaa42ad258c
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / scheduledthreadpool / TestingScheduledThreadPoolModuleFactory.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.scheduledthreadpool;
9
10 import java.util.Arrays;
11 import java.util.HashSet;
12 import java.util.List;
13 import java.util.Set;
14
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.manager.testingservices.seviceinterface
21         .TestingScheduledThreadPoolServiceInterface;
22 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
23 import org.opendaylight.controller.config.spi.Module;
24 import org.opendaylight.controller.config.spi.ModuleFactory;
25
26 public class TestingScheduledThreadPoolModuleFactory implements ModuleFactory {
27     public static final String NAME = "scheduled";
28
29     private static List<Class<? extends TestingThreadPoolServiceInterface>> ifc = Arrays
30             .asList(TestingScheduledThreadPoolServiceInterface.class, TestingThreadPoolServiceInterface.class);
31
32     @Override
33     public boolean isModuleImplementingServiceInterface(
34             Class<? extends AbstractServiceInterface> serviceInterface) {
35         return ifc.contains(serviceInterface);
36     }
37
38     @Override
39     public String getImplementationName() {
40         return NAME;
41     }
42
43     @Override
44     public Module createModule(String instanceName,
45             DependencyResolver dependencyResolver) {
46         return new TestingScheduledThreadPoolModule(new ModuleIdentifier(NAME,
47                 instanceName), null, null);
48     }
49
50     @Override
51     public Module createModule(String instanceName,
52             DependencyResolver dependencyResolver, DynamicMBeanWithInstance old)
53             throws Exception {
54         TestingScheduledThreadPoolImpl oldInstance;
55         try {
56             oldInstance = (TestingScheduledThreadPoolImpl) old.getInstance();
57         } catch (ClassCastException e) {// happens after OSGi update
58             oldInstance = null;
59         }
60
61         TestingScheduledThreadPoolModule configBean = new TestingScheduledThreadPoolModule(
62                 new ModuleIdentifier(NAME, instanceName), old.getInstance(),
63                 oldInstance);
64         // copy attributes
65         configBean.setRecreate((Boolean) old.getAttribute("Recreate"));
66         return configBean;
67     }
68
69     @Override
70     public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory) {
71         return new HashSet<Module>();
72     }
73 }