2 * Copyright (c) 2013 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 implements ModuleFactory {
25 public static final String NAME = "fixed";
27 private static final Set<Class<? extends AbstractServiceInterface>> ifc = ImmutableSet.of(
28 (Class<? extends AbstractServiceInterface>) ModifiableThreadPoolServiceInterface.class,
29 TestingThreadPoolServiceInterface.class);
32 public String getImplementationName() {
37 public TestingFixedThreadPoolModule createModule(final String instanceName,
38 final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
39 return new TestingFixedThreadPoolModule(new ModuleIdentifier(NAME,
40 instanceName), null, null);
44 public Module createModule(final String instanceName,
45 final DependencyResolver dependencyResolver, final DynamicMBeanWithInstance old, final BundleContext bundleContext)
47 int threadCount = (Integer) old.getAttribute("ThreadCount");
48 // is the instance compatible?
49 TestingFixedThreadPool oldInstance;
51 // reconfigure existing instance
52 oldInstance = (TestingFixedThreadPool) old.getInstance();
53 } catch (ClassCastException e) {
54 // old instance will be closed, new needs to be created
57 TestingFixedThreadPoolModule result = new TestingFixedThreadPoolModule(
58 new ModuleIdentifier(NAME, instanceName), old.getInstance(),
60 result.setThreadCount(threadCount);
65 public boolean isModuleImplementingServiceInterface(
66 final Class<? extends AbstractServiceInterface> serviceInterface) {
67 return ifc.contains(serviceInterface);
71 public Set<Module> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, final BundleContext bundleContext) {
72 return new HashSet<Module>();
76 public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {