@Override public synchronized void freeze(final String scaleDownNodeID, final CoreRemotingConnection connectionToKeepOpen) { if (!started) return; failureCheckAndFlushThread.close(false); HashMap<Object, ConnectionEntry> connectionEntries = new HashMap<>(connections); // Now we ensure that no connections will process any more packets after this method is // complete then send a disconnect packet for (Entry<Object, ConnectionEntry> entry : connectionEntries.entrySet()) { RemotingConnection conn = entry.getValue().connection; if (conn.equals(connectionToKeepOpen)) continue; if (logger.isTraceEnabled()) { logger.trace("Sending connection.disconnection packet to " + conn); } if (!conn.isClient()) { conn.disconnect(scaleDownNodeID, false); removeConnection(entry.getKey()); } } }
conn.disconnect(criticalError);
@Test(timeout = 60000) public void testCloseIsSentOnConnectionClose() throws Exception { AmqpClient client = createAmqpClient(); AmqpConnection amqpConnection = client.connect(); try { for (RemotingConnection connection : server.getRemotingService().getConnections()) { server.getRemotingService().removeConnection(connection); connection.disconnect(true); } Wait.assertTrue(amqpConnection::isClosed); assertEquals(AmqpSupport.CONNECTION_FORCED, amqpConnection.getConnection().getRemoteCondition().getCondition()); } finally { amqpConnection.close(); } }