docs: synchronized protected void addSession(SFSession session,
                                           long masterTokenValidityInSecs, int heartbeatFrequencyInSecs)
    {
      boolean requireReschedule = false;
  
      long oldHeartBeatIntervalInSecs = this.heartBeatIntervalInSecs;
      this.heartBeatIntervalInSecs = (long) heartbeatFrequencyInSecs;
  
      if (this.heartBeatIntervalInSecs > masterTokenValidityInSecs / 4)
      {
        this.heartBeatIntervalInSecs = masterTokenValidityInSecs / 4;
      }
  
      LOGGER.debug("update heartbeat interval"
                   + " from {} to {}",
                   oldHeartBeatIntervalInSecs,
                   this.heartBeatIntervalInSecs);
  
      // heartbeat rescheduling required
      requireReschedule = true;
  
      // add session to the list to be heartbeated
      sessions.put(session, Boolean.TRUE);
  
      /*
       * Create scheduler if it is the first time. It uses a custom thread
       * factory that will create daemon thread so that it will not block
       * JVM from exiting.
       */
      if (this.scheduler == null)
      {
        LOGGER.debug("create heartbeat thread pool");
        this.scheduler = Executors.newScheduledThreadPool(
            1,
            new ThreadFactory()
            {
              @Override
              public Thread newThread(Runnable runnable)
              {
                Thread thread =
                    Executors.defaultThreadFactory().newThread(runnable);
                thread.setName("heartbeat (" + thread.getId() + ")");
                thread.setDaemon(true);
                return thread;
              }
            });
      }
  
      // schedule a heartbeat task if none exists
      if (heartbeatFuture == null)
      {
        LOGGER.debug("schedule heartbeat task");
        this.scheduleHeartbeat();
      }
      // or reschedule if the master token validity has been reduced (rare event)
      else if (requireReschedule)
      {
        LOGGER.debug("Cancel existing heartbeat task");
  
        // Cancel existing task if not started yet and reschedule
        if (heartbeatFuture.cancel(false))
        {
          LOGGER.debug("Canceled existing heartbeat task, reschedule");
          this.scheduleHeartbeat();
        }
        else
        {
          LOGGER.debug("Failed to cancel existing heartbeat task");
        }
      }
    }