private void scheduleClientHeartbeatCheck(final BaseClient client, SchedulerKey key) { // cancel previous heartbeat check scheduler.cancel(key); scheduler.schedule( key, new Runnable() { public void run() { client.disconnect(); log.debug( "Client with sessionId: {} disconnected due to heartbeat timeout", client.getSessionId()); } }, configuration.getHeartbeatTimeout(), TimeUnit.SECONDS); }
private void scheduleTimeout(final long index, final UUID sessionId, final AckCallback callback) { if (callback.getTimeout() == -1) { return; } SchedulerKey key = new SchedulerKey(Type.ACK_TIMEOUT, sessionId); scheduler.schedule( key, new Runnable() { @Override public void run() { removeCallback(sessionId, index); callback.onTimeout(); } }, callback.getTimeout(), TimeUnit.SECONDS); }
public void onHeartbeat(final BaseClient client) { if (!configuration.isHeartbeatsEnabled()) { return; } final SchedulerKey key = new SchedulerKey(Type.HEARBEAT_TIMEOUT, client.getSessionId()); // cancel heartbeat check because the client answered scheduler.cancel(key); scheduler.schedule( new Runnable() { public void run() { client.send(new Packet(PacketType.HEARTBEAT)); scheduleClientHeartbeatCheck(client, key); } }, configuration.getHeartbeatInterval(), TimeUnit.SECONDS); }