Interface WriteDemandEstimator
-
public interface WriteDemandEstimator
Provides an estimate for the value ofn
for calls toPublisherSource.Subscription.request(long)
perPublisherSource.Subscription
. A newWriteDemandEstimator
is created for eachPublisher
that is written. Any method of an instance ofWriteDemandEstimator
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
All Methods Instance Methods Abstract Methods 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 associatedPublisherSource.Subscription
.void
onItemWrite(java.lang.Object written, long writeBufferCapacityBeforeWrite, long writeBufferCapacityAfterWrite)
Callback whenever an item is written on the connection.
-
-
-
Method Detail
-
onItemWrite
void onItemWrite(java.lang.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 associatedPublisherSource.Subscription
.This method is invoked every time there could be a need to request more items from the write
Publisher
. This means that the suppliedwriteBufferCapacityInBytes
may include the capacity for which we have already requested the writePublisher
.- 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 associatedPublisherSource.Subscription
.
-
-