]> git.basschouten.com Git - openhab-addons.git/blob
beac2802615c777ce4fea2079b96e1039104691b
[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.pooling;
14
15 import org.apache.commons.pool2.PooledObject;
16 import org.apache.commons.pool2.impl.EvictionConfig;
17 import org.apache.commons.pool2.impl.EvictionPolicy;
18 import org.openhab.io.transport.modbus.internal.pooling.ModbusSlaveConnectionFactoryImpl.PooledConnection;
19
20 import net.wimpi.modbus.net.ModbusSlaveConnection;
21
22 /**
23  * Eviction policy, i.e. policy for deciding when to close idle, unused connections.
24  *
25  * Connections are evicted according to {@link PooledConnection} maybeResetConnection method.
26  *
27  * @author Sami Salonen - Initial contribution
28  */
29 public class ModbusSlaveConnectionEvictionPolicy implements EvictionPolicy<ModbusSlaveConnection> {
30
31     @Override
32     public boolean evict(EvictionConfig config, PooledObject<ModbusSlaveConnection> underTest, int idleCount) {
33         return ((PooledConnection) underTest).maybeResetConnection("evict");
34     }
35 }