Fix checkstyle issues to enforce it
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / threadpool / TestingFixedThreadPoolModuleFactory.java
1 /*
2  * Copyright (c) 2013, 2017 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 com.google.common.collect.ImmutableSet;
11 import java.util.HashSet;
12 import java.util.Set;
13 import org.opendaylight.controller.config.api.DependencyResolver;
14 import org.opendaylight.controller.config.api.DependencyResolverFactory;
15 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
16 import org.opendaylight.controller.config.api.ModuleIdentifier;
17 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
18 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.ModifiableThreadPoolServiceInterface;
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 import org.osgi.framework.BundleContext;
23
24 public class TestingFixedThreadPoolModuleFactory extends AbstractTestingFixedThreadPoolModuleFactory
25         implements ModuleFactory {
26     public static final String NAME = "fixed";
27
28     private static final Set<Class<? extends AbstractServiceInterface>> IFC = ImmutableSet.of(
29             (Class<? extends AbstractServiceInterface>) ModifiableThreadPoolServiceInterface.class,
30             TestingThreadPoolServiceInterface.class);
31
32     @Override
33     public String getImplementationName() {
34         return NAME;
35     }
36
37     @Override
38     public TestingFixedThreadPoolModule createModule(final String instanceName,
39             final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
40         return new TestingFixedThreadPoolModule(new ModuleIdentifier(NAME, instanceName), null, null);
41     }
42
43     @Override
44     public Module createModule(final String instanceName, final DependencyResolver dependencyResolver,
45             final DynamicMBeanWithInstance old, final BundleContext bundleContext) 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 (final ClassCastException e) {
53             // old instance will be closed, new needs to be created
54             oldInstance = null;
55         }
56         TestingFixedThreadPoolModule result = new TestingFixedThreadPoolModule(new ModuleIdentifier(NAME, instanceName),
57                 old.getInstance(), oldInstance);
58         result.setThreadCount(threadCount);
59         return result;
60     }
61
62     @Override
63     public boolean isModuleImplementingServiceInterface(
64             final Class<? extends AbstractServiceInterface> serviceInterface) {
65         return IFC.contains(serviceInterface);
66     }
67
68     @Override
69     public Set<Module> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory,
70             final BundleContext bundleContext) {
71         return new HashSet<>();
72     }
73
74     @Override
75     public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {
76         return IFC;
77     }
78 }