/** * Obtains the last activity time as a {@link ZonedDateTime}. * * @return The last activity time. */ default ZonedDateTime getLastActivityZoned() { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(getLastActivityTime()), ZoneOffset.systemDefault()); }
@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; } } }