@Override
        public CompletableFuture<Void> onConnectionClosing(Object handback)
        {
            final OutgoingServerSession session = (OutgoingServerSession)handback;

            CompletableFuture<Void> result = CompletableFuture.runAsync(() -> Log.debug("Closing outgoing server session with address {} and streamID {}.", session.getAddress(), session.getStreamID()));

            // Remove all the domains that were registered for this server session.
            final Collection<CompletableFuture<Void>> tasks = new ArrayList<>();
            for (DomainPair domainPair : session.getOutgoingDomainPairs()) {
                tasks.add(CompletableFuture.runAsync(() -> server.getRoutingTable().removeServerRoute(domainPair)));
            }

            return result.thenCompose(e -> CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0])));
        }
Handle an outgoing server-to-server session that just closed.

@param handback The session that just closed
@return a Future representing pending completion of the event listener invocation.
xmppserver/src/main/java/org/jivesoftware/openfire/SessionManager.java