java.lang.Object
net.i2p.router.transport.OutboundMessageRegistry
Tracks outbound messages.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classPeriodically removes entries that were never answered.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Set<OutNetMessage> Set of active OutNetMessage (for quick removal and selector fetching).private final OutboundMessageRegistry.CleanupTaskTimer removing stale entries.private final RouterContextThe router sending the messages.private final LogLogger for this class.private final List<MessageSelector> List of currently active MessageSelector instances.private final Map<MessageSelector, Object> Map of active MessageSelector to either an OutNetMessage or a List of OutNetMessages causing it (for quick removal).Constructor Summary
ConstructorsConstructorDescriptionOutboundMessageRegistry(RouterContext context) Builds the empty selector tables and creates the expiry cleanup task.Method Summary
Modifier and TypeMethodDescriptiongetOriginalMessages(I2NPMessage message) Retrieve all messages that are waiting for the specified message.registerPending(MessageSelector replySelector, ReplyJob onReply, Job onTimeout) Registers a new, empty OutNetMessage, with the reply and timeout jobs specified.voidRegister the message.private voidregisterPending(OutNetMessage msg, boolean allowEmpty) Add a message to the pending registry, optionally allowing a null payload.voidrestart()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.voidshutdown()Does something @since 0.8.8.voidRemoves a message that is no longer waiting for a reply, so a later reply that still arrives is not handed to a cancelled request.
Field Details
_log
Logger for this class._selectors
List of currently active MessageSelector instances._selectorToMessage
Map of active MessageSelector to either an OutNetMessage or a List of OutNetMessages causing it (for quick removal)._activeMessages
Set of active OutNetMessage (for quick removal and selector fetching). Apparently only used for dup detection inregisterPending(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 inTransportImpl.afterSend(OutNetMessage, boolean)it does requeue a previous ONM if allowRequeue=true._cleanupTask
Timer removing stale entries._context
The router sending the messages.
Constructor Details
OutboundMessageRegistry
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
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-nullonTimeout- may be null- Returns:
- a dummy OutNetMessage where getMessage() is null. Use it to call
unregisterPending(OutNetMessage)later if desired.
registerPending
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
Add a message to the pending registry, optionally allowing a null payload.- Parameters:
msg- the message to register; its reply selector must be non-nullallowEmpty- is msg.getMessage() allowed to be null?
unregisterPending
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