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.scheduledthreadpool;
10 import java.io.Closeable;
11 import java.util.List;
12 import java.util.concurrent.Executor;
13 import java.util.concurrent.ScheduledExecutorService;
14 import java.util.concurrent.ScheduledThreadPoolExecutor;
16 import org.opendaylight.controller.config.api.runtime.HierarchicalRuntimeBeanRegistration;
17 import org.opendaylight.controller.config.api.runtime.RootRuntimeBeanRegistrator;
18 import org.opendaylight.controller.config.manager.testingservices.scheduledthreadpool.runtimebeans
19 .TestingScheduledRuntimeBean;
20 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolIfc;
22 import com.google.common.collect.Lists;
24 public class TestingScheduledThreadPoolImpl implements TestingThreadPoolIfc,
25 TestingScheduledThreadPoolIfc, Closeable {
26 private static volatile int numberOfCloseMethodCalls = 0;
27 private final ScheduledThreadPoolExecutor executor;
28 private final RootRuntimeBeanRegistrator runtimeBeanRegistrator;
30 public static final List<ScheduledThreadPoolExecutor> allExecutors = Lists
33 public TestingScheduledThreadPoolImpl(
34 RootRuntimeBeanRegistrator runtimeBeanRegistrator, int corePoolSize) {
35 this.runtimeBeanRegistrator = runtimeBeanRegistrator;
36 executor = new ScheduledThreadPoolExecutor(corePoolSize);
37 allExecutors.add(executor);
38 HierarchicalRuntimeBeanRegistration hierarchicalRuntimeBeanRegistration = runtimeBeanRegistrator
39 .registerRoot(new TestingScheduledRuntimeBean());
40 hierarchicalRuntimeBeanRegistration.register("a", "b",
41 new TestingScheduledRuntimeBean());
46 numberOfCloseMethodCalls++;
47 runtimeBeanRegistrator.close();
52 public ScheduledExecutorService getScheduledExecutor() {
57 public Executor getExecutor() {
62 public int getMaxNumberOfThreads() {
63 return executor.getCorePoolSize();
66 public static void cleanUp() {
67 for (ScheduledThreadPoolExecutor executor : allExecutors) {
71 numberOfCloseMethodCalls = 0;
74 public static int getNumberOfCloseMethodCalls() {
75 return numberOfCloseMethodCalls;