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 com.google.common.collect.Lists;
11 import java.io.Closeable;
12 import java.util.List;
13 import java.util.concurrent.Executor;
14 import java.util.concurrent.ScheduledExecutorService;
15 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.TestingScheduledRuntimeBean;
19 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolIfc;
21 public class TestingScheduledThreadPoolImpl implements TestingThreadPoolIfc,
22 TestingScheduledThreadPoolIfc, Closeable {
23 private static volatile int numberOfCloseMethodCalls = 0;
24 private final ScheduledThreadPoolExecutor executor;
25 private final RootRuntimeBeanRegistrator runtimeBeanRegistrator;
27 public static final List<ScheduledThreadPoolExecutor> allExecutors = Lists
30 public TestingScheduledThreadPoolImpl(
31 RootRuntimeBeanRegistrator runtimeBeanRegistrator, int corePoolSize) {
32 this.runtimeBeanRegistrator = runtimeBeanRegistrator;
33 executor = new ScheduledThreadPoolExecutor(corePoolSize);
34 allExecutors.add(executor);
35 HierarchicalRuntimeBeanRegistration hierarchicalRuntimeBeanRegistration = runtimeBeanRegistrator
36 .registerRoot(new TestingScheduledRuntimeBean());
37 hierarchicalRuntimeBeanRegistration.register("a", "b",
38 new TestingScheduledRuntimeBean());
43 numberOfCloseMethodCalls++;
44 runtimeBeanRegistrator.close();
49 public ScheduledExecutorService getScheduledExecutor() {
54 public Executor getExecutor() {
59 public int getMaxNumberOfThreads() {
60 return executor.getCorePoolSize();
63 public static void cleanUp() {
64 for (ScheduledThreadPoolExecutor executor : allExecutors) {
68 numberOfCloseMethodCalls = 0;
71 public static int getNumberOfCloseMethodCalls() {
72 return numberOfCloseMethodCalls;