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