2 * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.manager.testingservices.threadpool;
10 import com.google.common.collect.ImmutableSet;
11 import java.util.HashSet;
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;
24 public class TestingFixedThreadPoolModuleFactory extends AbstractTestingFixedThreadPoolModuleFactory
25 implements ModuleFactory {
26 public static final String NAME = "fixed";
28 private static final Set<Class<? extends AbstractServiceInterface>> IFC = ImmutableSet.of(
29 (Class<? extends AbstractServiceInterface>) ModifiableThreadPoolServiceInterface.class,
30 TestingThreadPoolServiceInterface.class);
33 public String getImplementationName() {
38 public TestingFixedThreadPoolModule createModule(final String instanceName,
39 final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
40 return new TestingFixedThreadPoolModule(new ModuleIdentifier(NAME, instanceName), null, null);
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;
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
56 TestingFixedThreadPoolModule result = new TestingFixedThreadPoolModule(new ModuleIdentifier(NAME, instanceName),
57 old.getInstance(), oldInstance);
58 result.setThreadCount(threadCount);
63 public boolean isModuleImplementingServiceInterface(
64 final Class<? extends AbstractServiceInterface> serviceInterface) {
65 return IFC.contains(serviceInterface);
69 public Set<Module> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory,
70 final BundleContext bundleContext) {
71 return new HashSet<>();
75 public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {