All Implemented Interfaces:
Runnable

public class SocketTimeoutextends SimpleTimer2.TimedEvent
Implements one or two timers; one for inactivity, that is reset by resetTimer(), and optionally, a total time since instantiation, that is configured by setTotalTimeoutPeriod(long).

On timer expiration, this will close a provided socket, and/or run a configured job.

Deprecated for external use. It is only used by EepGet, its subclasses, and Syndie. Take care not to break Syndie. The only advantage seems to be a total timeout period, which is the second argument to EepGet.fetch(long, long, long), which is most likely always set to -1.

Not for use by plugins or external applications, subject to change.

Use socket.setsotimeout instead?

  • Field Details

    • _targetSocket

      private volatile Socket _targetSocket
      The socket this timeout watches.
    • _startTime

      private final long _startTime
      When the timeout was created.
    • _inactivityDelay

      private volatile long _inactivityDelay
      Quiet time past which the socket times out, in ms.
    • _lastActivity

      private volatile long _lastActivity
      When the socket last carried data.
    • _totalTimeoutTime

      private volatile long _totalTimeoutTime
      Absolute deadline past which the socket times out.
    • _cancelled

      private volatile boolean _cancelled
      True once the timeout will not fire.
    • _command

      private volatile Runnable _command
      What runs when the timeout fires.
  • Constructor Details

    • SocketTimeout

      public SocketTimeout(long delay)
      Create a timer that runs a command after a period of socket inactivity.
      Parameters:
      delay - The inactivity delay, greater than zero
    • SocketTimeout

      public SocketTimeout(Socket socket, long delay)
      If socket is non-null, or is set later by setSocket(Socket), it will be closed when the timer expires.
      Parameters:
      socket - may be null
      delay - The inactivity delay, greater than zero
  • Method Details

    • timeReached

      public void timeReached()
      Description copied from class: SimpleTimer2.TimedEvent
      Called when this event's scheduled time arrives. Must NOT block. For periodic events, call schedule(period) at the end to self-reschedule.
      Specified by:
      timeReached in class SimpleTimer2.TimedEvent
    • cancel

      public boolean cancel()
      Change in return value from void to boolean in 0.9.3 accidentally broke Syndie, sorry. Recompile Syndie to fix it.
      Overrides:
      cancel in class SimpleTimer2.TimedEvent
      Returns:
      true if the event will not execute, false if already idle/cancelled
    • setSocket

      public void setSocket(Socket s)
      If non-null, will be closed when the timer expires.
      Parameters:
      s - the socket to close on expiry, or null to leave the socket alone
    • resetTimer

      public void resetTimer()
      Call when there is activity.
    • setInactivityTimeout

      public void setInactivityTimeout(long delay)
      Changes the delay provided in the constructor.
      Parameters:
      delay - greater than zero
    • setTotalTimeoutPeriod

      public void setTotalTimeoutPeriod(long timeoutPeriod)
      If greater than zero, must be greater than the inactivity timeout.
      Parameters:
      timeoutPeriod - Time since constructed, or less than or equal to zero to disable
    • setTimeoutCommand

      public void setTimeoutCommand(Runnable job)
      If non-null, will be run when the timer expires.
      Parameters:
      job - the command to run on expiry, or null to leave the current command in place
    • toString

      public String toString()
      Description copied from class: SimpleTimer2.TimedEvent
      Timer summary for log messages.
      Overrides:
      toString in class SimpleTimer2.TimedEvent
      Returns:
      the simple class name for log messages