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.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.ModifiableThreadPoolServiceInterface;
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;
22 import java.util.Collections;
23 import java.util.HashSet;
26 public class TestingFixedThreadPoolModuleFactory implements ModuleFactory {
27 public static final String NAME = "fixed";
29 private static Set<Class<? extends AbstractServiceInterface>> ifc = Collections.unmodifiableSet(Sets.newHashSet(
30 (Class<? extends AbstractServiceInterface>) ModifiableThreadPoolServiceInterface.class,
31 TestingThreadPoolServiceInterface.class));
34 public String getImplementationName() {
39 public TestingFixedThreadPoolModule createModule(String instanceName,
40 DependencyResolver dependencyResolver, BundleContext bundleContext) {
41 return new TestingFixedThreadPoolModule(new ModuleIdentifier(NAME,
42 instanceName), null, null);
46 public Module createModule(String instanceName,
47 DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext bundleContext)
49 int threadCount = (Integer) old.getAttribute("ThreadCount");
50 // is the instance compatible?
51 TestingFixedThreadPool oldInstance;
53 // reconfigure existing instance
54 oldInstance = (TestingFixedThreadPool) old.getInstance();
55 } catch (ClassCastException e) {
56 // old instance will be closed, new needs to be created
59 TestingFixedThreadPoolModule result = new TestingFixedThreadPoolModule(
60 new ModuleIdentifier(NAME, instanceName), old.getInstance(),
62 result.setThreadCount(threadCount);
67 public boolean isModuleImplementingServiceInterface(
68 Class<? extends AbstractServiceInterface> serviceInterface) {
69 return ifc.contains(serviceInterface);
73 public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext bundleContext) {
74 return new HashSet<Module>();
78 public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {