java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
org.klomp.snark.UDPTrackerClient.ReplyWaiter
- All Implemented Interfaces:
Runnable
- Enclosing class:
UDPTrackerClient
Callback for replies.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe action the request carried.private final byte[]The request payload that was sent.private UDPTrackerClient.TrackerResponseThe parsed reply, until it arrives.private final UDPTrackerClient.TrackerThe tracker the request was sent to.private UDPTrackerClient.WaitStateCurrent state of this request.private final intTransaction id matching the reply.Fields inherited from class SimpleTimer2.TimedEvent
_state, DEFAULT_FUZZModifier and TypeFieldDescriptionprotected SimpleTimer2.TimedEventStateState of the current event.protected static final intDefault fuzz threshold in milliseconds.Constructor Summary
ConstructorsConstructorDescriptionReplyWaiter(int tid, UDPTrackerClient.Tracker tracker, int action, byte[] payload, long toWait) Either wait on this object with a timeout, or use non-null Runnables.Method Summary
Modifier and TypeMethodDescriptionintThe expected action.intgetID()The ID.byte[]The payload.The reply object, may be null depending on what happened.The sent-to tracker.getState()The current state of this request.voidgotReply(boolean success) Will notify this.voidWill notify this.voidschedule(long toWait) Reset to the INIT state.private voidWill notify this and run onReply.voidTimer callback on timeout.toString()String form of the reply waiter.Methods inherited from class SimpleTimer2.TimedEvent
cancel, forceReschedule, reschedule, reschedule, run, setFuzz, setPoolModifier and TypeMethodDescriptionbooleancancel()Cancel the timed event.voidforceReschedule(long timeoutMs) Always use the new time - ignores fuzz.voidreschedule(long timeoutMs) Use the earliest of the new time and the old time May be called from within timeReached(), but schedule() is better there.voidreschedule(long timeoutMs, boolean useEarliestTime) May be called from within timeReached(), but schedule() is better there.voidrun()voidsetFuzz(int fuzz) Reschedule threshold in ms.voidsetPool(SimpleTimer2 pool) Timer pool for this event.
Field Details
tid
private final int tidTransaction id matching the reply.sentTo
The tracker the request was sent to.action
private final int actionThe action the request carried.data
private final byte[] dataThe request payload that was sent.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 ingetReplyObject().- Parameters:
tid- the transaction id of the requesttracker- the tracker being queriedaction- the tracker action numberpayload- the request bytes to sendtoWait- the time to wait for the reply, in ms
Method Details
getID
public int getID()The ID.- Returns:
- the i d
getSentTo
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
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
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
Will notify this and run onReply. Also removes from _sentQueries and calls heardFrom().- Parameters:
state- the new state of this request
gotResponse
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:
schedulein classSimpleTimer2.TimedEvent- Parameters:
toWait- delay in ms
timeReached
public void timeReached()Timer callback on timeout.- Specified by:
timeReachedin classSimpleTimer2.TimedEvent
toString
String form of the reply waiter.- Overrides:
toStringin classSimpleTimer2.TimedEvent- Returns:
- the simple class name for log messages