Example usage for org.apache.commons.pool2 KeyedObjectPool invalidateObject

List of usage examples for org.apache.commons.pool2 KeyedObjectPool invalidateObject

Introduction

In this page you can find the example usage for org.apache.commons.pool2 KeyedObjectPool invalidateObject.

Prototype

void invalidateObject(K key, V obj) throws Exception;

Source Link

Document

Invalidates an object from the pool.

Usage

From source file:org.openhab.io.transport.modbus.internal.ModbusManagerImpl.java

private void invalidate(ModbusSlaveEndpoint endpoint, Optional<ModbusSlaveConnection> connection) {
    KeyedObjectPool<ModbusSlaveEndpoint, ModbusSlaveConnection> pool = connectionPool;
    if (pool == null) {
        return;/*from w  w  w . j  a  va2 s  .  c o m*/
    }
    long start = System.currentTimeMillis();
    connection.ifPresent(con -> {
        try {
            pool.invalidateObject(endpoint, con);
        } catch (Exception e) {
            logger.warn("Error invalidating connection in pool for endpoint {}. Error was: {} {}", endpoint,
                    e.getClass().getName(), e.getMessage(), e);
        }
    });
    logger.trace("invalidating connection for endpoint {} took {} ms", endpoint,
            System.currentTimeMillis() - start);
}