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.io.transport.modbus.internal;
15 import org.apache.commons.pool2.KeyedPooledObjectFactory;
16 import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
17 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.io.transport.modbus.endpoint.ModbusSlaveEndpoint;
22 import net.wimpi.modbus.net.ModbusSlaveConnection;
25 * Pool for modbus connections.
27 * Only one connection is allowed to be active at a time.
29 * @author Sami Salonen - Initial contribution
33 public class ModbusConnectionPool extends GenericKeyedObjectPool<ModbusSlaveEndpoint, ModbusSlaveConnection> {
35 public ModbusConnectionPool(KeyedPooledObjectFactory<ModbusSlaveEndpoint, ModbusSlaveConnection> factory) {
36 super(factory, new ModbusPoolConfig());
40 public void setConfig(@Nullable GenericKeyedObjectPoolConfig<ModbusSlaveConnection> conf) {
43 } else if (!(conf instanceof ModbusPoolConfig)) {
44 throw new IllegalArgumentException("Only ModbusPoolConfig accepted!");
46 super.setConfig(conf);