dcb121abfad4263584f77a94f22b4bdb78f96d9c
[controller.git] / opendaylight / config / threadpool-config-impl / src / main / java / org / opendaylight / controller / config / threadpool / util / FixedThreadPoolWrapper.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.ExecutorService;
13 import java.util.concurrent.Executors;
14 import java.util.concurrent.ThreadFactory;
15 import java.util.concurrent.ThreadPoolExecutor;
16 import org.opendaylight.controller.config.threadpool.ThreadPool;
17
18 /**
19  * Implementation of {@link ThreadPool} using fixed number of threads wraps
20  * {@link ExecutorService}.
21  */
22 /**
23  * To be removed in Nitrogen
24  */
25 @Deprecated
26 public class FixedThreadPoolWrapper implements ThreadPool, Closeable {
27
28     private final ThreadPoolExecutor executor;
29
30     public FixedThreadPoolWrapper(int threadCount, ThreadFactory factory) {
31         this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadCount, factory);
32         executor.prestartAllCoreThreads();
33     }
34
35     @Override
36     public ExecutorService getExecutor() {
37         return Executors.unconfigurableExecutorService(executor);
38     }
39
40     @Override
41     public void close() {
42         executor.shutdown();
43     }
44
45     @Override
46     public int getMaxThreadCount() {
47         return executor.getMaximumPoolSize();
48     }
49
50     public void setMaxThreadCount(int maxThreadCount) {
51         executor.setCorePoolSize(maxThreadCount);
52         executor.setMaximumPoolSize(maxThreadCount);
53     }
54 }