Interface WriteDemandEstimator


public interface WriteDemandEstimator
Provides an estimate for the value of n for calls to PublisherSource.Subscription.request(long) per PublisherSource.Subscription. A new WriteDemandEstimator is created for each Publisher that is written. Any method of an instance of WriteDemandEstimator will never be called concurrently with the same or other methods of the same instance. This means that implementations do not have to worry about thread-safety.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    estimateRequestN(long writeBufferCapacityInBytes)
    Given the current capacity of the write buffer, supply how many items to request next from the associated PublisherSource.Subscription.
    void
    onItemWrite(Object written, long writeBufferCapacityBeforeWrite, long writeBufferCapacityAfterWrite)
    Callback whenever an item is written on the connection.
  • Method Details

    • onItemWrite

      void onItemWrite(Object written, long writeBufferCapacityBeforeWrite, long writeBufferCapacityAfterWrite)
      Callback whenever an item is written on the connection.

      Write buffer capacity may not correctly reflect size of the object written. Hence capacity before may not necessarily be more than capacity after write.

      Parameters:
      written - Item that was written.
      writeBufferCapacityBeforeWrite - Capacity of the write buffer before this item was written.
      writeBufferCapacityAfterWrite - Capacity of the write buffer after this item was written.
    • estimateRequestN

      long estimateRequestN(long writeBufferCapacityInBytes)
      Given the current capacity of the write buffer, supply how many items to request next from the associated PublisherSource.Subscription.

      This method is invoked every time there could be a need to request more items from the write Publisher. This means that the supplied writeBufferCapacityInBytes may include the capacity for which we have already requested the write Publisher.

      Parameters:
      writeBufferCapacityInBytes - Current write buffer capacity. This will always be non-negative and will be 0 if buffer is full.
      Returns:
      Number of items to request next from the associated PublisherSource.Subscription. Implementation may assume that whatever is returned here is sent as-is to the associated PublisherSource.Subscription.