Fix checkstyle issues to enforce it
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / scheduledthreadpool / TestingScheduledThreadPoolModuleFactory.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.scheduledthreadpool;
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.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 import org.osgi.framework.BundleContext;
23
24 public class TestingScheduledThreadPoolModuleFactory implements ModuleFactory {
25     public static final String NAME = "scheduled";
26
27     private static Set<Class<? extends AbstractServiceInterface>> ifc = ImmutableSet.of(
28             (Class<? extends AbstractServiceInterface>) TestingScheduledThreadPoolServiceInterface.class,
29             TestingThreadPoolServiceInterface.class);
30
31     @Override
32     public boolean isModuleImplementingServiceInterface(
33             final Class<? extends AbstractServiceInterface> serviceInterface) {
34         return ifc.contains(serviceInterface);
35     }
36
37     @Override
38     public String getImplementationName() {
39         return NAME;
40     }
41
42     @Override
43     public Module createModule(final String instanceName, final DependencyResolver dependencyResolver,
44             final BundleContext bundleContext) {
45         return new TestingScheduledThreadPoolModule(new ModuleIdentifier(NAME, instanceName), null, null);
46     }
47
48     @Override
49     public Module createModule(final String instanceName, final DependencyResolver dependencyResolver,
50             final DynamicMBeanWithInstance old, final BundleContext bundleContext) throws Exception {
51         TestingScheduledThreadPoolImpl oldInstance;
52         try {
53             oldInstance = (TestingScheduledThreadPoolImpl) old.getInstance();
54         } catch (final ClassCastException e) {
55             // happens after OSGi update
56             oldInstance = null;
57         }
58
59         TestingScheduledThreadPoolModule configBean = new TestingScheduledThreadPoolModule(
60                 new ModuleIdentifier(NAME, instanceName), old.getInstance(), oldInstance);
61         // copy attributes
62         configBean.setRecreate((Boolean) old.getAttribute("Recreate"));
63         return configBean;
64     }
65
66     @Override
67     public Set<Module> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory,
68             final BundleContext bundleContext) {
69         return new HashSet<>();
70     }
71
72     @Override
73     public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {
74         return ifc;
75     }
76 }