Bug 116 - Revisit SanityTest
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / threadpool / TestingFixedThreadPoolModuleFactory.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.threadpool;
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.manager.testingservices.seviceinterface.ModifiableThreadPoolServiceInterface;
16 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
17 import org.opendaylight.controller.config.spi.Module;
18 import org.opendaylight.controller.config.spi.ModuleFactory;
19 import org.osgi.framework.BundleContext;
20
21 import java.util.Arrays;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25
26 public class TestingFixedThreadPoolModuleFactory implements ModuleFactory {
27     public static final String NAME = "fixed";
28     private static List<Class<? extends TestingThreadPoolServiceInterface>> ifc = Arrays
29             .asList(ModifiableThreadPoolServiceInterface.class, TestingThreadPoolServiceInterface.class);
30
31     @Override
32     public String getImplementationName() {
33         return NAME;
34     }
35
36     @Override
37     public TestingFixedThreadPoolModule createModule(String instanceName,
38             DependencyResolver dependencyResolver, BundleContext bundleContext) {
39         return new TestingFixedThreadPoolModule(new ModuleIdentifier(NAME,
40                 instanceName), null, null);
41     }
42
43     @Override
44     public Module createModule(String instanceName,
45             DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext bundleContext)
46             throws Exception {
47         int threadCount = (Integer) old.getAttribute("ThreadCount");
48         // is the instance compatible?
49         TestingFixedThreadPool oldInstance;
50         try {
51             // reconfigure existing instance
52             oldInstance = (TestingFixedThreadPool) old.getInstance();
53         } catch (ClassCastException e) {
54             // old instance will be closed, new needs to be created
55             oldInstance = null;
56         }
57         TestingFixedThreadPoolModule result = new TestingFixedThreadPoolModule(
58                 new ModuleIdentifier(NAME, instanceName), old.getInstance(),
59                 oldInstance);
60         result.setThreadCount(threadCount);
61         return result;
62     }
63
64     @Override
65     public boolean isModuleImplementingServiceInterface(
66             Class<? extends AbstractServiceInterface> serviceInterface) {
67         return ifc.contains(serviceInterface);
68     }
69
70     @Override
71     public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext bundleContext) {
72         return new HashSet<Module>();
73     }
74 }