Class HeartBeatTimeoutTask

java.lang.Object
java.util.TimerTask
it.polimi.ingsw.Network.HeartBeatTimeoutTask
All Implemented Interfaces:
Runnable

public class HeartBeatTimeoutTask extends TimerTask
Timeout timer task waiting to close the socket in case it is not cancelled in time.
  • Field Details

  • Constructor Details

    • HeartBeatTimeoutTask

      private HeartBeatTimeoutTask(SocketWrapper sock)
      Private constructor setting up the attributes for the timeout task
      Parameters:
      sock - the socket to close in case of timeout
  • Method Details

    • startAndGetTimer

      public static Timer startAndGetTimer(SocketWrapper socketWrapper, long timeoutDuration)
      Sets up a single, non repeating timer counting down to the timeout.
      Parameters:
      socketWrapper - the socket to close if the timer runs out
      timeoutDuration - the timeout duration in milliseconds
      Returns:
      the timer that is counting down the timeout, calling Timer.cancel() on it will prevent the timeout task from running, effectively resetting the timeout.
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Specified by:
      run in class TimerTask