java.lang.Object
net.i2p.router.transport.OutboundMessageRegistry

public class OutboundMessageRegistryextends Object
Tracks outbound messages.
  • Field Details

    • _log

      private final Log _log
      Logger for this class.
    • _selectors

      private final List<MessageSelector> _selectors
      List of currently active MessageSelector instances.
    • _selectorToMessage

      private final Map<MessageSelector, Object> _selectorToMessage
      Map of active MessageSelector to either an OutNetMessage or a List of OutNetMessages causing it (for quick removal).
    • _activeMessages

      private final Set<OutNetMessage> _activeMessages
      Set of active OutNetMessage (for quick removal and selector fetching). Apparently only used for dup detection in registerPending(OutNetMessage, boolean). Changed to concurrent, but it could perhaps be removed completely, It would seem difficult to add a dup since every OutNetMessage is different, and it's generally instantiated just before ctx.outNetMessagePool().add(). But in TransportImpl.afterSend(OutNetMessage, boolean) it does requeue a previous ONM if allowRequeue=true.
    • _cleanupTask

      private final OutboundMessageRegistry.CleanupTask _cleanupTask
      Timer removing stale entries.
    • _context

      private final RouterContext _context
      The router sending the messages.
  • Constructor Details

    • OutboundMessageRegistry

      public OutboundMessageRegistry(RouterContext context)
      Builds the empty selector tables and creates the expiry cleanup task.
      Parameters:
      context - router context, retained for later message creation
  • Method Details

    • shutdown

      public void shutdown()
      Does something @since 0.8.8.
    • restart

      public void restart()
      Clears the registry, for a transport that is restarting: nothing that was awaiting a reply can still be answered, so the pending messages are dropped.
    • getOriginalMessages

      public List<OutNetMessage> getOriginalMessages(I2NPMessage message)
      Retrieve all messages that are waiting for the specified message. In addition, those matches may include instructions to either continue or not continue waiting for further replies - if it should continue, the matched message remains in the registry, but if it shouldn't continue, the matched message is removed from the registry.

      This is called only by InNetMessagePool.

      Parameters:
      message - Payload received that may be a reply to something we sent
      Returns:
      non-null List of OutNetMessage describing messages that were waiting for the payload
    • registerPending

      public OutNetMessage registerPending(MessageSelector replySelector, ReplyJob onReply, Job onTimeout)
      Registers a new, empty OutNetMessage, with the reply and timeout jobs specified. The onTimeout job is called at replySelector.getExpiration() (if no reply is received by then).
      Parameters:
      replySelector - non-null; The same selector may be used for more than one message.
      onReply - non-null
      onTimeout - may be null
      Returns:
      a dummy OutNetMessage where getMessage() is null. Use it to call unregisterPending(OutNetMessage) later if desired.
    • registerPending

      public void registerPending(OutNetMessage msg)
      Register the message. Each message must have a non-null selector at msg.getReplySelector(). The same selector may be used for more than one message.
      Parameters:
      msg - msg.getMessage() and msg.getReplySelector() must be non-null
    • registerPending

      private void registerPending(OutNetMessage msg, boolean allowEmpty)
      Add a message to the pending registry, optionally allowing a null payload.
      Parameters:
      msg - the message to register; its reply selector must be non-null
      allowEmpty - is msg.getMessage() allowed to be null?
    • unregisterPending

      public void unregisterPending(OutNetMessage msg)
      Removes a message that is no longer waiting for a reply, so a later reply that still arrives is not handed to a cancelled request. A message whose selector still carries other waiters stays registered.
      Parameters:
      msg - may be be null, if non-null should have a non-null selector