java.lang.Object
net.i2p.client.impl.MessageState
Contains the state of a payload message being sent to a peer.
Originally was a general-purpose waiter. Then we got rid of guaranteed delivery. Then we stopped waiting for accept in best-effort delivery. Brought back to life for asynchronous status delivery to the client.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumStatus of the message being tracked.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe app context.private final longWhen the message was queued.private final longWhen the message expires.private MessageIdThe id assigned by the connection, once sent.private final SendMessageStatusListenerListener notified of the message status.private final LogLogger for the message status.private final longThe nonce of the message being tracked.private final StringLog prefix naming the session.private final I2PSessionThe session the message was sent on.private MessageState.StateCurrent status of the message.Constructor Summary
ConstructorsConstructorDescriptionMessageState(I2PAppContext ctx, long nonce, String prefix) For synchronous waiting for accept withwaitForAccept(long).MessageState(I2PAppContext ctx, long nonce, I2PSession session, long expires, SendMessageStatusListener listener) Track a sent message's delivery state for asynchronous notification.Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancel the message by injecting a canceled status.longReturn the elapsed time.longReturn the expiration time.Return the message ID.private voidlocked_update(int status) Record a status update, advancing the state only when it moves forward.voidreceive(int status) Process a message status from the router and notify the listener.voidMessage ID assigned to this message.voidwaitForAccept(long expiration) For guaranteed/best effort only.booleanReport whether the message was accepted for delivery.booleanReport whether the message was delivered successfully.
Field Details
_context
The app context._log
Logger for the message status._nonce
private final long _nonceThe nonce of the message being tracked._prefix
Log prefix naming the session._id
The id assigned by the connection, once sent._created
private final long _createdWhen the message was queued._expires
private final long _expiresWhen the message expires._listener
Listener notified of the message status._session
The session the message was sent on._state
Current status of the message.
Constructor Details
MessageState
For synchronous waiting for accept withwaitForAccept(long). UNUSED.- Parameters:
ctx- the context supplying the clock and log used for the sixty second lifetime and for warningsnonce- the transaction nonce this message was sent underprefix- text prepended to every log line so this send can be told apart from others
MessageState
public MessageState(I2PAppContext ctx, long nonce, I2PSession session, long expires, SendMessageStatusListener listener) Track a sent message's delivery state for asynchronous notification.- Parameters:
ctx- the context supplying the clock and log used to time the wait and to report warningsnonce- the transaction nonce this message was sent undersession- the session the message was sent through, also used as the log prefixexpires- absolute time (not interval)listener- notified on each state change while the message has not yet expired
Method Details
receive
public void receive(int status) Process a message status from the router and notify the listener.- Parameters:
status- one of the MessageStatusMessage status codes the router reported for this message
setMessageId
Message ID assigned to this message.- Parameters:
id- the message ID the router assigned to the sent message
getMessageId
getElapsed
public long getElapsed()Return the elapsed time.- Returns:
- milliseconds elapsed on the router clock since the message was created
getExpires
public long getExpires()Return the expiration time.- Returns:
- the absolute router clock time at which the wait expires
waitForAccept
For guaranteed/best effort only. Not really used.- Parameters:
expiration- absolute time in milliseconds at which the wait is abandoned, not an interval- Throws:
InterruptedException- if the waiting thread is interrupted before a status arrives or the deadline passes
locked_update
private void locked_update(int status) Record a status update, advancing the state only when it moves forward.- Parameters:
status- the MessageStatusMessage status code just received
wasAccepted
public boolean wasAccepted()Report whether the message was accepted for delivery.- Returns:
- true if accepted (fixme and not failed)
wasSuccessful
public boolean wasSuccessful()Report whether the message was delivered successfully.- Returns:
- true if successful
cancel
public void cancel()Cancel the message by injecting a canceled status.