net.i2p.util

## Class SocketTimeout

- java.lang.Object
- - net.i2p.util.SimpleTimer2.TimedEvent
  - - net.i2p.util.SocketTimeout

- All Implemented Interfaces:
    Runnable

      public class SocketTimeout
      extends 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(). 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(headerTimeout, totalTimeout, inactivityTimeout), which is most likely always set to -1. Not for use by plugins or external applications, subject to change. Use socket.setsotimeout instead?

- - ### Field Summary

    - ### Fields inherited from class net.i2p.util.SimpleTimer2.TimedEvent

      `_state, DEFAULT_FUZZ`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SocketTimeout(long delay)`
    `SocketTimeout(Socket socket, long delay)` If socket is non-null, or is set later by setSocket(), it will be closed when the timer expires.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `cancel()` Change in return value from void to boolean in 0.9.3 accidentally broke Syndie, sorry.
    `void` | `resetTimer()` Call when there is activity
    `void` | `setInactivityTimeout(long delay)` Changes the delay provided in the constructor
    `void` | `setSocket(Socket s)` If non-null, will be closed when the timer expires.
    `void` | `setTimeoutCommand(Runnable job)` If non-null, will be run when the timer expires.
    `void` | `setTotalTimeoutPeriod(long timeoutPeriod)` If greater than zero, must be greater than the inactivity timeout.
    `void` | `timeReached()` Simple interface for events to be queued up and notified on expiration the time requested has been reached (this call should NOT block, otherwise the whole SimpleTimer gets backed up)
    `String` | `toString()` So the critical "please report" message above isn't so ugly

    - ### Methods inherited from class net.i2p.util.SimpleTimer2.TimedEvent

      `forceReschedule, reschedule, reschedule, run, schedule, setFuzz`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SocketTimeout

          public SocketTimeout(long delay)

      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(), it will be closed when the timer expires.
      Parameters:
        `socket` - may be null
        `delay` - The inactivity delay, greater than zero

  - ### Method Detail

    - #### 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 cancelled

    - #### 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

    - #### setSocket

          public void setSocket(Socket s)

      If non-null, will be closed when the timer expires.

    - #### setTimeoutCommand

          public void setTimeoutCommand(Runnable job)

      If non-null, will be run when the timer expires.

    - #### 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

    - #### timeReached

          public void timeReached()

      Description copied from class: `SimpleTimer2.TimedEvent`
      Simple interface for events to be queued up and notified on expiration the time requested has been reached (this call should NOT block, otherwise the whole SimpleTimer gets backed up)
      Specified by:
        `timeReached` in class `SimpleTimer2.TimedEvent`

    - #### toString

          public String toString()

      Description copied from class: `SimpleTimer2.TimedEvent`
      So the critical "please report" message above isn't so ugly
      Overrides:
        `toString` in class `SimpleTimer2.TimedEvent`