java.lang.Object
net.i2p.client.impl.MessageState

class MessageStateextends Object
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.

  • Field Details

    • _context

      private final I2PAppContext _context
      The app context.
    • _log

      private final Log _log
      Logger for the message status.
    • _nonce

      private final long _nonce
      The nonce of the message being tracked.
    • _prefix

      private final String _prefix
      Log prefix naming the session.
    • _id

      private MessageId _id
      The id assigned by the connection, once sent.
    • _created

      private final long _created
      When the message was queued.
    • _expires

      private final long _expires
      When the message expires.
    • _listener

      private final SendMessageStatusListener _listener
      Listener notified of the message status.
    • _session

      private final I2PSession _session
      The session the message was sent on.
    • _state

      private MessageState.State _state
      Current status of the message.
  • Constructor Details

    • MessageState

      public MessageState(I2PAppContext ctx, long nonce, String prefix)
      For synchronous waiting for accept with waitForAccept(long). UNUSED.
      Parameters:
      ctx - the context supplying the clock and log used for the sixty second lifetime and for warnings
      nonce - the transaction nonce this message was sent under
      prefix - 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 warnings
      nonce - the transaction nonce this message was sent under
      session - the session the message was sent through, also used as the log prefix
      expires - 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

      public void setMessageId(MessageId id)
      Message ID assigned to this message.
      Parameters:
      id - the message ID the router assigned to the sent message
    • getMessageId

      public MessageId getMessageId()
      Return the message ID.
      Returns:
      the message id
    • 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

      public void waitForAccept(long expiration) throws InterruptedException
      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.