Package org.osgi.util.pushstream
Class ThresholdPushbackPolicy<T,U extends BlockingQueue<PushEvent<? extends T>>>
java.lang.Object
org.osgi.util.pushstream.ThresholdPushbackPolicy<T,U>
- Type Parameters:
T
- The type of objects in thePushEvent
U
- The type of the Queue used in the user specified buffer
- All Implemented Interfaces:
PushbackPolicy<T,
U>
public final class ThresholdPushbackPolicy<T,U extends BlockingQueue<PushEvent<? extends T>>>
extends Object
implements PushbackPolicy<T,U>
Provides a configurable
PushbackPolicy
implementation that returns
zero back pressure until the buffer fills beyond the supplied threshold. Once
the threshold is reached back pressure is returned based on the supplied
parameters.
The starting level of the back pressure once the threshold is exceeded is
defined using the initial
parameter. Additional back pressure is
applied for each queued item over the threshold. The amount of this
additional back pressure is defined by the increment
parameter.
The following common use cases are supported:
- The increment size can be zero, returning the initial value as a fixed back pressure after the threshold is exceeded.
- The initial value can be zero, returning a linearly increasing back pressure from zero once the threshold is exceeded
- Since:
- 1.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
U extends BlockingQueue<PushEvent<? extends T>>>
ThresholdPushbackPolicy<T,U> createIncrementalThresholdPushbackPolicy
(int threshold, long increment) A simple configuration, where the increment size is used as the initial back pressure.static <T,
U extends BlockingQueue<PushEvent<? extends T>>>
ThresholdPushbackPolicy<T,U> createSimpleThresholdPushbackPolicy
(int threshold) A simple configuration with an initial back pressure of one and and increase increment size of one.static <T,
U extends BlockingQueue<PushEvent<? extends T>>>
ThresholdPushbackPolicy<T,U> createThresholdPushbackPolicy
(int threshold, long initial, long increment) Provides aThresholdPushbackPolicy
with an individual configuration for all possible parameters.long
Given the current state of the queue, determine the level of back pressure that should be applied
-
Method Details
-
createSimpleThresholdPushbackPolicy
public static <T,U extends BlockingQueue<PushEvent<? extends T>>> ThresholdPushbackPolicy<T,U> createSimpleThresholdPushbackPolicy(int threshold) A simple configuration with an initial back pressure of one and and increase increment size of one.- Parameters:
threshold
- the queue size limit after which back pressure will be applied- Returns:
- a new
ThresholdPushbackPolicy
- Throws:
IllegalArgumentException
- if any of the given values is lower then zero- See Also:
-
createIncrementalThresholdPushbackPolicy
public static <T,U extends BlockingQueue<PushEvent<? extends T>>> ThresholdPushbackPolicy<T,U> createIncrementalThresholdPushbackPolicy(int threshold, long increment) A simple configuration, where the increment size is used as the initial back pressure.- Parameters:
increment
- the increments in which the pressure increasesthreshold
- the queue size limit after which back pressure will be applied- Returns:
- a new
ThresholdPushbackPolicy
- Throws:
IllegalArgumentException
- if any of the given values is lower then zero- See Also:
-
createThresholdPushbackPolicy
public static <T,U extends BlockingQueue<PushEvent<? extends T>>> ThresholdPushbackPolicy<T,U> createThresholdPushbackPolicy(int threshold, long initial, long increment) Provides aThresholdPushbackPolicy
with an individual configuration for all possible parameters.- Parameters:
increment
- the increments in which the pressure increases.initial
- the initial back pressure which defines the floor after the threshold is exceededthreshold
- the queue size limit after which back pressure will be applied- Returns:
- a new
ThresholdPushbackPolicy
- Throws:
IllegalArgumentException
- if any of the given values is lower then zero
-
pushback
Description copied from interface:PushbackPolicy
Given the current state of the queue, determine the level of back pressure that should be applied- Specified by:
pushback
in interfacePushbackPolicy<T,
U extends BlockingQueue<PushEvent<? extends T>>> - Returns:
- a back pressure value in nanoseconds
- Throws:
Exception
-