2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.cbus.internal;
15 import java.util.HashMap;
17 import java.util.concurrent.ThreadPoolExecutor;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.common.ThreadPoolManager;
23 import com.daveoxley.cbus.CGateThreadPool;
24 import com.daveoxley.cbus.CGateThreadPoolExecutor;
27 * The {@link CBusThreadPool} is responsible for executing jobs from a threadpool
29 * @author John Harvey - Initial contribution
33 public class CBusThreadPool extends CGateThreadPool {
35 private final Map<String, @Nullable CGateThreadPoolExecutor> executorMap = new HashMap<>();
38 protected synchronized CGateThreadPoolExecutor CreateExecutor(@Nullable String name) {
39 if (name == null || name.isEmpty()) {
43 CGateThreadPoolExecutor executor = executorMap.get(name);
44 if (executor != null) {
47 CGateThreadPoolExecutor newExecutor = new CBusThreadPoolExecutor(name);
48 executorMap.put(name, newExecutor);
53 public class CBusThreadPoolExecutor extends CGateThreadPoolExecutor {
54 private final ThreadPoolExecutor threadPool;
56 public CBusThreadPoolExecutor(@Nullable String poolName) {
57 threadPool = (ThreadPoolExecutor) ThreadPoolManager.getPool("binding.cbus-" + poolName);
61 protected void execute(@Nullable Runnable runnable) {
62 if (runnable != null) {
63 threadPool.execute(runnable);