-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[modbus] Check and disconnect idle connections without transactions
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
- Loading branch information
Showing
4 changed files
with
141 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...org/openhab/io/transport/modbus/internal/pooling/ModbusSlaveConnectionEvictionPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.io.transport.modbus.internal.pooling; | ||
|
||
import org.apache.commons.pool2.PooledObject; | ||
import org.apache.commons.pool2.impl.EvictionConfig; | ||
import org.apache.commons.pool2.impl.EvictionPolicy; | ||
import org.openhab.io.transport.modbus.internal.pooling.ModbusSlaveConnectionFactoryImpl.PooledConnection; | ||
|
||
import net.wimpi.modbus.net.ModbusSlaveConnection; | ||
|
||
/** | ||
* Eviction policy, i.e. policy for deciding when to close idle, unused connections. | ||
* | ||
* Connections are evicted according to {@link PooledConnection} maybeResetConnection method. | ||
* | ||
* @author Sami Salonen - Initial contribution | ||
*/ | ||
public class ModbusSlaveConnectionEvictionPolicy implements EvictionPolicy<ModbusSlaveConnection> { | ||
|
||
@Override | ||
public boolean evict(EvictionConfig config, PooledObject<ModbusSlaveConnection> underTest, int idleCount) { | ||
return ((PooledConnection) underTest).maybeResetConnection("evict"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters