Merge "creating a default subnet"
[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
17 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
18
19 /**
20  * Implementation of {@link ScheduledThreadPool} wraps
21  * {@link ScheduledExecutorService}.
22  */
23 public class ScheduledThreadPoolWrapper implements ScheduledThreadPool, Closeable {
24
25     private final ScheduledThreadPoolExecutor executor;
26     private final int threadCount;
27
28     public ScheduledThreadPoolWrapper(int threadCount, ThreadFactory factory) {
29         this.threadCount = threadCount;
30         this.executor = new ScheduledThreadPoolExecutor(threadCount, factory);
31         executor.prestartAllCoreThreads();
32     }
33
34     @Override
35     public ScheduledExecutorService getExecutor() {
36         return Executors.unconfigurableScheduledExecutorService(executor);
37     }
38
39     @Override
40     public void close() {
41         executor.shutdown();
42     }
43
44     @Override
45     public int getMaxThreadCount() {
46         return threadCount;
47     }
48
49 }