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.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, TestingScheduledThreadPoolIfc, Closeable {
22 private static volatile int numberOfCloseMethodCalls = 0;
23 private final ScheduledThreadPoolExecutor executor;
24 private final RootRuntimeBeanRegistrator runtimeBeanRegistrator;
26 public static final List<ScheduledThreadPoolExecutor> ALLEXECUTORS = Lists.newLinkedList();
28 public TestingScheduledThreadPoolImpl(final RootRuntimeBeanRegistrator runtimeBeanRegistrator,
29 final int corePoolSize) {
30 this.runtimeBeanRegistrator = runtimeBeanRegistrator;
31 executor = new ScheduledThreadPoolExecutor(corePoolSize);
32 ALLEXECUTORS.add(executor);
33 HierarchicalRuntimeBeanRegistration hierarchicalRuntimeBeanRegistration = runtimeBeanRegistrator
34 .registerRoot(new TestingScheduledRuntimeBean());
35 hierarchicalRuntimeBeanRegistration.register("a", "b", new TestingScheduledRuntimeBean());
40 numberOfCloseMethodCalls++;
41 runtimeBeanRegistrator.close();
46 public ScheduledExecutorService getScheduledExecutor() {
51 public Executor getExecutor() {
56 public int getMaxNumberOfThreads() {
57 return executor.getCorePoolSize();
60 public static void cleanUp() {
61 for (ScheduledThreadPoolExecutor executor : ALLEXECUTORS) {
65 numberOfCloseMethodCalls = 0;
68 public static int getNumberOfCloseMethodCalls() {
69 return numberOfCloseMethodCalls;