Merge "On openflow plugin restart, NPE in tx poller"
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / scheduledthreadpool / TestingScheduledThreadPoolModuleFactory.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.scheduledthreadpool;
9
10 import com.google.common.collect.Sets;
11 import org.opendaylight.controller.config.api.DependencyResolver;
12 import org.opendaylight.controller.config.api.DependencyResolverFactory;
13 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
14 import org.opendaylight.controller.config.api.ModuleIdentifier;
15 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
16 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingScheduledThreadPoolServiceInterface;
17 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
18 import org.opendaylight.controller.config.spi.Module;
19 import org.opendaylight.controller.config.spi.ModuleFactory;
20 import org.osgi.framework.BundleContext;
21
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.Set;
25
26 public class TestingScheduledThreadPoolModuleFactory implements ModuleFactory {
27     public static final String NAME = "scheduled";
28
29     private static Set<Class<? extends AbstractServiceInterface>> ifc = Collections.unmodifiableSet(Sets.newHashSet(
30             (Class<? extends AbstractServiceInterface>) TestingScheduledThreadPoolServiceInterface.class,
31                     TestingThreadPoolServiceInterface.class));
32
33     @Override
34     public boolean isModuleImplementingServiceInterface(
35             Class<? extends AbstractServiceInterface> serviceInterface) {
36         return ifc.contains(serviceInterface);
37     }
38
39     @Override
40     public String getImplementationName() {
41         return NAME;
42     }
43
44     @Override
45     public Module createModule(String instanceName,
46             DependencyResolver dependencyResolver, BundleContext bundleContext) {
47         return new TestingScheduledThreadPoolModule(new ModuleIdentifier(NAME,
48                 instanceName), null, null);
49     }
50
51     @Override
52     public Module createModule(String instanceName,
53             DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext bundleContext)
54             throws Exception {
55         TestingScheduledThreadPoolImpl oldInstance;
56         try {
57             oldInstance = (TestingScheduledThreadPoolImpl) old.getInstance();
58         } catch (ClassCastException e) {// happens after OSGi update
59             oldInstance = null;
60         }
61
62         TestingScheduledThreadPoolModule configBean = new TestingScheduledThreadPoolModule(
63                 new ModuleIdentifier(NAME, instanceName), old.getInstance(),
64                 oldInstance);
65         // copy attributes
66         configBean.setRecreate((Boolean) old.getAttribute("Recreate"));
67         return configBean;
68     }
69
70     @Override
71     public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext bundleContext) {
72         return new HashSet<Module>();
73     }
74
75     @Override
76     public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {
77         return ifc;
78     }
79
80
81 }