Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public void onAck(SocketIOClient client, Packet packet) {
   SchedulerKey key = new SchedulerKey(Type.ACK_TIMEOUT, client.getSessionId());
   scheduler.cancel(key);
   AckCallback callback = removeCallback(client.getSessionId(), packet.getAckId());
   if (callback != null) {
     callback.onSuccess();
   }
 }
Exemplo n.º 3
0
  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);
  }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 @Override
 public void onDisconnect(BaseClient client) {
   scheduler.cancel(new SchedulerKey(Type.HEARBEAT_TIMEOUT, client.getSessionId()));
 }
 public void stop() {
   scheduler.shutdown();
 }