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