java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
org.klomp.snark.UDPTrackerClient.ReplyWaiter
All Implemented Interfaces:
Runnable
Enclosing class:
UDPTrackerClient

private class UDPTrackerClient.ReplyWaiterextends SimpleTimer2.TimedEvent
Callback for replies.
  • Field Details

    • tid

      private final int tid
      Transaction id matching the reply.
    • sentTo

      private final UDPTrackerClient.Tracker sentTo
      The tracker the request was sent to.
    • action

      private final int action
      The action the request carried.
    • data

      private final byte[] data
      The request payload that was sent.
    • replyObject

      private UDPTrackerClient.TrackerResponse replyObject
      The parsed reply, until it arrives.
    • state

      Current state of this request.
  • Constructor Details

    • ReplyWaiter

      public ReplyWaiter(int tid, UDPTrackerClient.Tracker tracker, int action, byte[] payload, long toWait)
      Either wait on this object with a timeout, or use non-null Runnables. Any sent data to be remembered may be stored by setSentObject(). Reply object may be in getReplyObject().
      Parameters:
      tid - the transaction id of the request
      tracker - the tracker being queried
      action - the tracker action number
      payload - the request bytes to send
      toWait - the time to wait for the reply, in ms
  • Method Details

    • getID

      public int getID()
      The ID.
      Returns:
      the i d
    • getSentTo

      public UDPTrackerClient.Tracker getSentTo()
      The sent-to tracker.
      Returns:
      the sent to
    • getExpectedAction

      public int getExpectedAction()
      The expected action.
      Returns:
      the BEP 15 action type the reply must carry
    • getPayload

      public byte[] getPayload()
      The payload.
      Returns:
      the already-built datagram, as sent or as to be resent
    • getReplyObject

      public UDPTrackerClient.TrackerResponse getReplyObject()
      The reply object, may be null depending on what happened. Cast to the expected type.
      Returns:
      may be null depending on what happened. Cast to expected type.
    • getState

      public UDPTrackerClient.WaitState getState()
      The current state of this request.
      Returns:
      the wait state
    • gotReply

      public void gotReply(boolean success)
      Will notify this. Also removes from _sentQueries and calls heardFrom(). Sets state to SUCCESS or FAIL.
      Parameters:
      success - true if the tracker replied without an error
    • setState

      private void setState(UDPTrackerClient.WaitState state)
      Will notify this and run onReply. Also removes from _sentQueries and calls heardFrom().
      Parameters:
      state - the new state of this request
    • gotResponse

      public void gotResponse(UDPTrackerClient.TrackerResponse resp)
      Will notify this. Also removes from _sentQueries and calls heardFrom(). Sets state to SUCCESS.
      Parameters:
      resp - the response received
    • schedule

      public void schedule(long toWait)
      Reset to the INIT state.
      Overrides:
      schedule in class SimpleTimer2.TimedEvent
      Parameters:
      toWait - delay in ms
    • timeReached

      public void timeReached()
      Timer callback on timeout.
      Specified by:
      timeReached in class SimpleTimer2.TimedEvent
    • toString

      public String toString()
      String form of the reply waiter.
      Overrides:
      toString in class SimpleTimer2.TimedEvent
      Returns:
      the simple class name for log messages