## net.i2p.router.tunnel
Class BatchedPreprocessor

    java.lang.Object
      net.i2p.router.tunnel.TrivialPreprocessor
          net.i2p.router.tunnel.BatchedPreprocessor

All Implemented Interfaces:
  TunnelGateway.QueuePreprocessor

Direct Known Subclasses:
  BatchedRouterPreprocessor

    public class BatchedPreprocessor

extends TrivialPreprocessor

Batching preprocessor that will briefly delay the sending of a message if it doesn't fill up a full tunnel message, in which case it queues up an additional flush task. This is a very simple threshold algorithm - as soon as there is enough data for a full tunnel message, it is sent. If after the delay there still isn't enough data, what is available is sent and padded.

Field Summary
`(package private) static long` `DEFAULT_DELAY`

Fields inherited from class net.i2p.router.tunnel.TrivialPreprocessor
`_context, _dataCache, _hashCache, _ivCache, IV_SIZE, PREPROCESSED_SIZE`

Constructor Summary
`BatchedPreprocessor(I2PAppContext ctx, java.lang.String name)`

Method Summary
`long` `getDelayAmount()` how long do we want to wait before flushing
`protected long` `getSendDelay()` wait up to 2 seconds before sending a small message
`boolean` `preprocessQueue(java.util.List pending, TunnelGateway.Sender sender, TunnelGateway.Receiver rec)` Return true if there were messages remaining, and we should queue up a delayed flush to clear them
`protected void` `send(java.util.List pending, int startAt, int sendThrough, TunnelGateway.Sender sender, TunnelGateway.Receiver rec)` Preprocess the messages from the pending list, grouping items startAt through sendThrough (though only part of the last one may be fully sent), delivering them through the sender/receiver.

Methods inherited from class net.i2p.router.tunnel.TrivialPreprocessor
`getInstructionAugmentationSize, getInstructionsSize, notePreprocessing, preprocess, writeFirstFragment, writeSubsequentFragment`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_DELAY

    static long DEFAULT_DELAY

Constructor Detail

### BatchedPreprocessor

    public BatchedPreprocessor(I2PAppContext ctx,
                               java.lang.String name)

Method Detail

### getSendDelay

    protected long getSendDelay()

  wait up to 2 seconds before sending a small message

### getDelayAmount

    public long getDelayAmount()

  how long do we want to wait before flushing

  Specified by:
    `getDelayAmount` in interface `TunnelGateway.QueuePreprocessor`
  Overrides:
    `getDelayAmount` in class `TrivialPreprocessor`

### preprocessQueue

    public boolean preprocessQueue(java.util.List pending,
                                   TunnelGateway.Sender sender,
                                   TunnelGateway.Receiver rec)

  Description copied from class: `TrivialPreprocessor`
  Return true if there were messages remaining, and we should queue up a delayed flush to clear them

  Specified by:
    `preprocessQueue` in interface `TunnelGateway.QueuePreprocessor`
  Overrides:
    `preprocessQueue` in class `TrivialPreprocessor`
  Parameters:
    `pending` - list of Pending objects for messages either unsent or partly sent. This list should be update with any values removed (the preprocessor owns the lock)
  Returns:
    true if we should delay before preprocessing again

### send

    protected void send(java.util.List pending,
                        int startAt,
                        int sendThrough,
                        TunnelGateway.Sender sender,
                        TunnelGateway.Receiver rec)

  Preprocess the messages from the pending list, grouping items startAt through sendThrough (though only part of the last one may be fully sent), delivering them through the sender/receiver.

  Parameters:
    `startAt` - first index in pending to send (inclusive)
    `sendThrough` - last index in pending to send (inclusive)