BUG-8: migrate newMBeanProxy() -> newMXBeanProxy()
[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.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,
44             final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
45         return new TestingScheduledThreadPoolModule(new ModuleIdentifier(NAME,
46                 instanceName), null, null);
47     }
48
49     @Override
50     public Module createModule(final String instanceName,
51             final DependencyResolver dependencyResolver, final DynamicMBeanWithInstance old, final BundleContext bundleContext)
52             throws Exception {
53         TestingScheduledThreadPoolImpl oldInstance;
54         try {
55             oldInstance = (TestingScheduledThreadPoolImpl) old.getInstance();
56         } catch (ClassCastException e) {// happens after OSGi update
57             oldInstance = null;
58         }
59
60         TestingScheduledThreadPoolModule configBean = new TestingScheduledThreadPoolModule(
61                 new ModuleIdentifier(NAME, instanceName), old.getInstance(),
62                 oldInstance);
63         // copy attributes
64         configBean.setRecreate((Boolean) old.getAttribute("Recreate"));
65         return configBean;
66     }
67
68     @Override
69     public Set<Module> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, final BundleContext bundleContext) {
70         return new HashSet<Module>();
71     }
72
73     @Override
74     public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {
75         return ifc;
76     }
77
78
79 }