private boolean discardAvailableConnections(long timeout, TimeUnit unit) throws InterruptedException { long start = System.nanoTime(); boolean success = true; for (Connection connection : connections) { success &= connection.close(timeout - Cluster.timeSince(start, unit), unit); open.decrementAndGet(); } return success; }
/** * Remove RabbitReconnector if it's not null (to prevent reconnect). Close connection if it's not * null. Swallow IOExceptions. * * @param conn * @param reconnector */ public static void closeConnectionAndRemoveReconnector( Connection conn, RabbitReconnector reconnector) { if (conn == null) { return; } if (reconnector != null) { conn.removeShutdownListener(reconnector); } try { conn.close(); } catch (IOException e) { e.printStackTrace(); // throw new RuntimeException(e); } }
public void shutdown() { for (ClientEndpoint endpoint : endpoints.values()) { try { endpoint.destroy(); } catch (LoginException e) { logger.finest(e.getMessage()); } try { final Connection conn = endpoint.getConnection(); if (conn.live()) { conn.close(); } } catch (Exception e) { logger.finest(e); } } endpoints.clear(); }
private void destroyEndpoint(ClientEndpoint endpoint, boolean closeImmediately) { if (endpoint != null) { logger.info("Destroying " + endpoint); try { endpoint.destroy(); } catch (LoginException e) { logger.warning(e); } final Connection connection = endpoint.getConnection(); if (closeImmediately) { try { connection.close(); } catch (Throwable e) { logger.warning("While closing client connection: " + connection, e); } } else { nodeEngine .getExecutionService() .schedule( new Runnable() { public void run() { if (connection.live()) { try { connection.close(); } catch (Throwable e) { logger.warning("While closing client connection: " + e.toString()); } } } }, 1111, TimeUnit.MILLISECONDS); } sendClientEvent(endpoint); } }