]> git.basschouten.com Git - openhab-addons.git/blob
e5430d9771d8ce5031888656aaee48ea05710c40
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.transport.modbus.internal;
14
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;
21
22 import net.wimpi.modbus.net.ModbusSlaveConnection;
23
24 /**
25  * Pool for modbus connections.
26  *
27  * Only one connection is allowed to be active at a time.
28  *
29  * @author Sami Salonen - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public class ModbusConnectionPool extends GenericKeyedObjectPool<ModbusSlaveEndpoint, ModbusSlaveConnection> {
34
35     public ModbusConnectionPool(KeyedPooledObjectFactory<ModbusSlaveEndpoint, ModbusSlaveConnection> factory) {
36         super(factory, new ModbusPoolConfig());
37     }
38
39     @Override
40     public void setConfig(@Nullable GenericKeyedObjectPoolConfig<ModbusSlaveConnection> conf) {
41         if (conf == null) {
42             return;
43         } else if (!(conf instanceof ModbusPoolConfig)) {
44             throw new IllegalArgumentException("Only ModbusPoolConfig accepted!");
45         }
46         super.setConfig(conf);
47     }
48 }