public void shutdown() { live = false; for (ObjectPool<ConnectionWrapper> pool : poolMap.values()) { pool.destroy(); } poolMap.clear(); }
public Connection getConnection(Address address) throws IOException { checkLive(); if (address == null) { throw new IllegalArgumentException("Target address is required!"); } final ObjectPool<ConnectionWrapper> pool = getConnectionPool(address); if (pool == null) { return null; } Connection connection = null; try { connection = pool.take(); } catch (Exception e) { if (logger.isFinestEnabled()) { logger.warning("Error during connection creation... To -> " + address, e); } } // Could be that this address is dead and that's why pool is not able to create and give a // connection. // We will call it again, and hopefully at some time LoadBalancer will give us the right target // for the connection. if (connection != null && !heartbeat.checkHeartBeat(connection)) { logger.warning(connection + " failed to heartbeat, closing..."); connection.close(); connection = null; } return connection; }
private void releaseConnection(ConnectionWrapper connection) { if (live) { final ObjectPool<ConnectionWrapper> pool = poolMap.get(connection.getRemoteEndpoint()); if (pool != null) { pool.release(connection); } else { connection.close(); } } else { connection.close(); } }
public void removeConnectionPool(Address address) { ObjectPool<ConnectionWrapper> pool = poolMap.remove(address); if (pool != null) { pool.destroy(); } }