Merge "Fix duplicate dependency warnings"
[controller.git] / opendaylight / config / threadpool-config-impl / src / main / java / org / opendaylight / controller / config / threadpool / util / ScheduledThreadPoolWrapper.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.config.threadpool.util;
10
11 import java.io.Closeable;
12 import java.util.concurrent.Executors;
13 import java.util.concurrent.ScheduledExecutorService;
14 import java.util.concurrent.ScheduledThreadPoolExecutor;
15 import java.util.concurrent.ThreadFactory;
16 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
17
18 /**
19  * Implementation of {@link ScheduledThreadPool} wraps
20  * {@link ScheduledExecutorService}.
21  */
22 public class ScheduledThreadPoolWrapper implements ScheduledThreadPool, Closeable {
23
24     private final ScheduledThreadPoolExecutor executor;
25     private final int threadCount;
26
27     public ScheduledThreadPoolWrapper(int threadCount, ThreadFactory factory) {
28         this.threadCount = threadCount;
29         this.executor = new ScheduledThreadPoolExecutor(threadCount, factory);
30         executor.prestartAllCoreThreads();
31     }
32
33     @Override
34     public ScheduledExecutorService getExecutor() {
35         return Executors.unconfigurableScheduledExecutorService(executor);
36     }
37
38     @Override
39     public void close() {
40         executor.shutdown();
41     }
42
43     @Override
44     public int getMaxThreadCount() {
45         return threadCount;
46     }
47
48 }