java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
org.klomp.snark.dht.KRPC.ReplyWaiter
- All Implemented Interfaces:
Runnable
- Enclosing class:
KRPC
Callback for replies.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MsgIDThe message id being tracked.private final RunnableRunnable run when the reply arrives.private final RunnableRunnable run when the reply times out.private intReply code received, zero until it arrives.private ObjectObject returned by the reply.private ObjectObject sent with the request.private final NodeInfoThe node the request was sent to.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(MsgID mID, NodeInfo nInfo, Runnable onReply, Runnable onTimeout) Either wait on this object with a timeout, or use non-null Runnables.Method Summary
All MethodsModifier and TypeMethodDescriptionintIf nonzero, we got a reply, andgetReplyObject()may contain something.Should contain null if getReplyCode is REPLY_PONG.The object stored with setSentObject().The destination the packet was sent to.voidWill notify this and run onReply.voidWill notify this but not run onReply or onTimeout, or remove from _sentQueries, or call heardFrom().voidOnly used for get_peers, to save the Info Hash.voidTimer callback on timeout.Methods inherited from class SimpleTimer2.TimedEvent
cancel, forceReschedule, reschedule, reschedule, run, schedule, setFuzz, setPool, toStringModifier 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()voidschedule(long timeoutMs) Schedule this event.voidsetFuzz(int fuzz) Reschedule threshold in ms.voidsetPool(SimpleTimer2 pool) Timer pool for this event.toString()Timer summary for log messages.
Field Details
mid
The message id being tracked.sentTo
The node the request was sent to.onReply
Runnable run when the reply arrives.onTimeout
Runnable run when the reply times out.replyCode
private volatile int replyCodeReply code received, zero until it arrives.sentObject
Object sent with the request.replyObject
Object returned by the reply.
Constructor Details
ReplyWaiter
Either wait on this object with a timeout, or use non-null Runnables. Any sent data to be remembered may be stored bysetSentObject(Object). Reply object may be in getReplyObject().- Parameters:
mID- the message ID of the query being awaitednInfo- the node the query was sent to, and whose reply is creditedonReply- must be fast, otherwise set to null and wait on this UNUSEDonTimeout- must be fast, otherwise set to null and wait on this UNUSED
Method Details
getSentTo
setSentObject
Only used for get_peers, to save the Info Hash.- Parameters:
o- the payload remembered alongside the query, read back bygetSentObject()
getSentObject
The object stored with setSentObject().- Returns:
- that stored with setSentObject()
getReplyObject
Should contain null if getReplyCode is REPLY_PONG. Should contain List<Hash> if getReplyCode is REPLY_PEERS. Should contain List<NodeInfo> if getReplyCode is REPLY_NODES. Should contain String if getReplyCode is > 200.- Returns:
- may be null depending on what happened. Cast to expected type.
getReplyCode
public int getReplyCode()If nonzero, we got a reply, andgetReplyObject()may contain something.- Returns:
- code or 0 if no error
gotReply
Will notify this and run onReply. Also removes from _sentQueries and callsKRPC.heardFrom(NodeInfo).- Parameters:
code- the reply status code, as returned bygetReplyCode()o- the parsed reply payload, stored in getReplyObject()
timeReached
public void timeReached()Timer callback on timeout.- Specified by:
timeReachedin classSimpleTimer2.TimedEvent
networkFail
public void networkFail()Will notify this but not run onReply or onTimeout, or remove from _sentQueries, or call heardFrom().