/** * Awaits the closure of the underlying channel, which implies that the close frame handshake * would have been performed. * * @param waitMillis The number of milliseconds to wait. * @return True if the endpoint was closed. * @throws InterruptedException If the thread was interrupted. */ default boolean awaitClose(int waitMillis) throws InterruptedException { return Await.bounded(waitMillis, () -> ! isOpen()); }
@Override public void run() { while (running) { try { final long now = System.currentTimeMillis(); for (E endpoint : endpoints) { if (! endpoint.isOpen()) { log.debug("Terminating defunct endpoint {}", endpoint); endpoint.terminate(); } else if (pingIntervalMillis != 0) { final long lastActivity = endpoint.getLastActivityTime(); if (now - lastActivity > pingIntervalMillis) { log.trace("Pinging {}", endpoint); endpoint.sendPing(); } } } } catch (Exception e) { log.error("Unexpected error", e); } try { Thread.sleep(scanIntervalMillis); } catch (InterruptedException e) { Thread.currentThread().interrupt(); continue; } } }