Class SlidingWindow
java.lang.Object
org.palladiosimulator.commons.designpatterns.AbstractObservable<ISlidingWindowListener>
org.palladiosimulator.experimentanalysis.SlidingWindow
- All Implemented Interfaces:
org.palladiosimulator.commons.designpatterns.IAbstractObservable<ISlidingWindowListener>
public abstract class SlidingWindow
extends org.palladiosimulator.commons.designpatterns.AbstractObservable<ISlidingWindowListener>
This class is an implementation of a fixed length sliding window.
Purpose of this window is to collect measurements of a certain kind that occur within the window length. These measurements are written into the window by a
Once the window is full, the window moves forward by a fixed increment and the collected measurements are propagated to all connected
Additionally, each window instance has an attached
Purpose of this window is to collect measurements of a certain kind that occur within the window length. These measurements are written into the window by a
SlidingWindowRecorder.Once the window is full, the window moves forward by a fixed increment and the collected measurements are propagated to all connected
ISlidingWindowListeners, e.g., certain
SlidingWindowAggregators.Additionally, each window instance has an attached
ISlidingWindowMoveOnStrategy that
defines how the collected data (i.e., the measurements) is adjusted when the window moves
forward.-
Constructor Summary
ConstructorsConstructorDescriptionSlidingWindow(javax.measure.Measure<Double, javax.measure.quantity.Duration> windowLength, javax.measure.Measure<Double, javax.measure.quantity.Duration> increment, javax.measure.Measure<Double, javax.measure.quantity.Duration> initialLowerBound, org.palladiosimulator.metricspec.MetricDescription acceptedMetrics, ISlidingWindowMoveOnStrategy moveOnStrategy) Initializes a new instance of theSlidingWindowclass with the given parameters.SlidingWindow(javax.measure.Measure<Double, javax.measure.quantity.Duration> windowLength, javax.measure.Measure<Double, javax.measure.quantity.Duration> increment, org.palladiosimulator.metricspec.MetricDescription acceptedMetrics, ISlidingWindowMoveOnStrategy moveOnStrategy) Initializes a new instance of theSlidingWindowclass with the given parameters.SlidingWindow(javax.measure.Measure<Double, javax.measure.quantity.Duration> windowLength, org.palladiosimulator.metricspec.MetricDescription acceptedMetrics, ISlidingWindowMoveOnStrategy moveOnStrategy) Initializes a new instance of theSlidingWindowclass with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected final booleanGets whether the metric accepted by this window is aBaseMetricDescription.voidaddMeasurement(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) Adds a new measurement to the data this window collects.protected final voidaddMeasurementInternal(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) This method adds the given measurement to the window data.final voidAttaches aISlidingWindowListenerinstance to this window.
Most commonly, the given listener is aSlidingWindowAggregator.protected voidcheckAddMeasurementPrerequisites(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) This method is intended to be overridden by subclasses.final voidflush()Discards the data (i.e., the measurements) currently collected by this window.final org.palladiosimulator.metricspec.MetricDescriptionGets the metric this window accepts.final List<ISlidingWindowListener>Gets the currently attached observers.final javax.measure.Measure<Double,javax.measure.quantity.Duration> Gets the current lower (i.e., left) bound of the window.javax.measure.Measure<Double,javax.measure.quantity.Duration> Gets the current upper bound of the window.javax.measure.Measure<Double,javax.measure.quantity.Duration> Gets the current, effective window length.final javax.measure.Measure<Double,javax.measure.quantity.Duration> Gets the value this window's lower bound is incremented by once the window moves on.final intGets the number of currently collected measurements.protected final javax.measure.Measure<Double,javax.measure.quantity.Duration> Gets the window length as specified inSlidingWindow(Measure, MetricDescription, ISlidingWindowMoveOnStrategy)orSlidingWindow(Measure, Measure, MetricDescription, ISlidingWindowMoveOnStrategy).
Note, that the current, effective window length might be smaller.final booleanisEmpty()Indicates if there are currently measurements available.protected final voidThis method is invoked once the sliding window is full.
All attachedISlidingWindowListenerare notified and the window moves on by the specified increment.Methods inherited from class org.palladiosimulator.commons.designpatterns.AbstractObservable
getEventDispatcher, getObservers, removeAllObserver, removeObserver
-
Constructor Details
-
SlidingWindow
public SlidingWindow(javax.measure.Measure<Double, javax.measure.quantity.Duration> windowLength, org.palladiosimulator.metricspec.MetricDescription acceptedMetrics, ISlidingWindowMoveOnStrategy moveOnStrategy) Initializes a new instance of theSlidingWindowclass with the given parameters.- Parameters:
windowLength- The length of the window, given in any arbitraryDuration. Additionally, this measure also denotes the window increment.acceptedMetrics- As each window only accepts measurements that adhere to a certain metric, aMetricDescriptionof must be specified.moveOnStrategy- TheISlidingWindowMoveOnStrategyinstance that defines how the collected data (i.e., the measurements) is adjusted when the window moves forward.- Throws:
IllegalArgumentException- In one of the following cases:- given window length is negative
acceptedMetricsormoveOnStrategyisnull
- See Also:
-
SlidingWindow
public SlidingWindow(javax.measure.Measure<Double, javax.measure.quantity.Duration> windowLength, javax.measure.Measure<Double, javax.measure.quantity.Duration> increment, org.palladiosimulator.metricspec.MetricDescription acceptedMetrics, ISlidingWindowMoveOnStrategy moveOnStrategy) Initializes a new instance of theSlidingWindowclass with the given parameters.- Parameters:
windowLength- The length of the window, given in any arbitraryDuration.increment- ThisMeasureindicates the increment by what the window is moved on, given in any arbitraryDuration.acceptedMetrics- As each window only accepts measurements that adhere to a certain metric, aMetricDescriptionof must be specified.moveOnStrategy- TheISlidingWindowMoveOnStrategyinstance that defines how the collected data (i.e., the measurements) is adjusted when the window moves forward.- Throws:
IllegalArgumentException- In one of the following cases:- given window length or increment is negative
acceptedMetricsormoveOnStrategyisnull
-
SlidingWindow
public SlidingWindow(javax.measure.Measure<Double, javax.measure.quantity.Duration> windowLength, javax.measure.Measure<Double, javax.measure.quantity.Duration> increment, javax.measure.Measure<Double, javax.measure.quantity.Duration> initialLowerBound, org.palladiosimulator.metricspec.MetricDescription acceptedMetrics, ISlidingWindowMoveOnStrategy moveOnStrategy) Initializes a new instance of theSlidingWindowclass with the given parameters.- Parameters:
windowLength- The length of the window, given in any arbitraryDuration.increment- ThisMeasureindicates the increment by what the window is moved on, given in any arbitraryDuration.initialLowerBound- ThisMeasureindicates the lower bound value at which the algorithm starts aggregating, given in any arbitraryDuration.acceptedMetrics- As each window only accepts measurements that adhere to a certain metric, aMetricDescriptionof must be specified.moveOnStrategy- TheISlidingWindowMoveOnStrategyinstance that defines how the collected data (i.e., the measurements) is adjusted when the window moves forward.- Throws:
IllegalArgumentException- In one of the following cases:- given window length or increment is negative
acceptedMetricsormoveOnStrategyisnull
-
-
Method Details
-
onWindowFullEvent
protected final void onWindowFullEvent()This method is invoked once the sliding window is full.
All attachedISlidingWindowListenerare notified and the window moves on by the specified increment. -
addMeasurement
public void addMeasurement(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) Adds a new measurement to the data this window collects.- Parameters:
newMeasurement- TheMeasuringValueinstance to add.- Throws:
IllegalArgumentException- If the given measurement isnullor does not adhere to the metric this window accepts.
-
checkAddMeasurementPrerequisites
protected void checkAddMeasurementPrerequisites(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) This method is intended to be overridden by subclasses. They might do so to check their additional (potentially more specific) prerequisites.- Parameters:
newMeasurement- TheMeasuringValueto be added to the window data.- Throws:
IllegalArgumentException- If the given measurement isnullor does not adhere to the metric this window accepts.
-
addMeasurementInternal
protected final void addMeasurementInternal(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) This method adds the given measurement to the window data. No prerequisite checks are performed.
As this method is intended to be used by subclasses when they overrideaddMeasurement(MeasuringValue), implementations should take care to callcheckAddMeasurementPrerequisites(MeasuringValue)beforehand to ensure uncorrupt window data.- Parameters:
newMeasurement- TheMeasurementto be added.
-
flush
public final void flush()Discards the data (i.e., the measurements) currently collected by this window. -
getAcceptedMetric
public final org.palladiosimulator.metricspec.MetricDescription getAcceptedMetric()Gets the metric this window accepts.- Returns:
- A
MetricDescriptiondenoting the metric this window accepts. - See Also:
-
SlidingWindow#addMeasurement(Measurement)
-
acceptsBaseMetric
protected final boolean acceptsBaseMetric()Gets whether the metric accepted by this window is aBaseMetricDescription. The same result is obtained by callinggetAcceptedMetric()and then doing a type check.- Returns:
trueif the metric is a base metric, otherwisefalse.- See Also:
-
getCurrentLowerBound
Gets the current lower (i.e., left) bound of the window.- Returns:
- A
Measuredenoting the current upper bound. - See Also:
-
getCurrentUpperBound
Gets the current upper bound of the window.- Returns:
- A
Measuredenoting the current upper bound. - See Also:
-
SimulationGovernedSlidingWindow#getEffectiveWindowLength()
-
getSpecifiedWindowLength
protected final javax.measure.Measure<Double,javax.measure.quantity.Duration> getSpecifiedWindowLength()Gets the window length as specified inSlidingWindow(Measure, MetricDescription, ISlidingWindowMoveOnStrategy)orSlidingWindow(Measure, Measure, MetricDescription, ISlidingWindowMoveOnStrategy).
Note, that the current, effective window length might be smaller.- Returns:
- A
Measuredenoting the specified window length. - See Also:
-
getEffectiveWindowLength
Gets the current, effective window length. Note that the effective window length might be smaller than specified inSlidingWindow(Measure, MetricDescription, ISlidingWindowMoveOnStrategy)orSlidingWindow(Measure, Measure, MetricDescription, ISlidingWindowMoveOnStrategy).- Returns:
- A
Measuredenoting the instantaneous effective window length. - See Also:
-
getIncrement
Gets the value this window's lower bound is incremented by once the window moves on.- Returns:
- A
Measuredenoting the window increment. - See Also:
-
isEmpty
public final boolean isEmpty()Indicates if there are currently measurements available.- Returns:
false, if yes, otherwisetrue
-
getNumberOfElements
public final int getNumberOfElements()Gets the number of currently collected measurements.- Returns:
- A nonnegative value denoting the number of elements.
-
addObserver
Attaches aISlidingWindowListenerinstance to this window.
Most commonly, the given listener is aSlidingWindowAggregator.- Specified by:
addObserverin interfaceorg.palladiosimulator.commons.designpatterns.IAbstractObservable<ISlidingWindowListener>- Overrides:
addObserverin classorg.palladiosimulator.commons.designpatterns.AbstractObservable<ISlidingWindowListener>- Parameters:
arg0- The listener to attach.- Throws:
IllegalArgumentException- If the given listener isnullor expects a metric other than this window's accepted one.- See Also:
-
getAttachedObservers
Gets the currently attached observers.- Returns:
- An unmodifiable list containing the attached
ISlidingWindowListeners.
-