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