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
ISlidingWindowListener
s, e.g., certain
SlidingWindowAggregator
s.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
ConstructorDescriptionSlidingWindow
(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 theSlidingWindow
class 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 theSlidingWindow
class 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 theSlidingWindow
class with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected final boolean
Gets whether the metric accepted by this window is aBaseMetricDescription
.void
addMeasurement
(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) Adds a new measurement to the data this window collects.protected final void
addMeasurementInternal
(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) This method adds the given measurement to the window data.final void
Attaches aISlidingWindowListener
instance to this window.
Most commonly, the given listener is aSlidingWindowAggregator
.protected void
checkAddMeasurementPrerequisites
(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement) This method is intended to be overridden by subclasses.final void
flush()
Discards the data (i.e., the measurements) currently collected by this window.final org.palladiosimulator.metricspec.MetricDescription
Gets 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 int
Gets 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 boolean
isEmpty()
Indicates if there are currently measurements available.protected final void
This method is invoked once the sliding window is full.
All attachedISlidingWindowListener
are 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 theSlidingWindow
class 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, aMetricDescription
of must be specified.moveOnStrategy
- TheISlidingWindowMoveOnStrategy
instance 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
acceptedMetrics
ormoveOnStrategy
isnull
- 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 theSlidingWindow
class with the given parameters.- Parameters:
windowLength
- The length of the window, given in any arbitraryDuration
.increment
- ThisMeasure
indicates 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, aMetricDescription
of must be specified.moveOnStrategy
- TheISlidingWindowMoveOnStrategy
instance 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
acceptedMetrics
ormoveOnStrategy
isnull
-
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 theSlidingWindow
class with the given parameters.- Parameters:
windowLength
- The length of the window, given in any arbitraryDuration
.increment
- ThisMeasure
indicates the increment by what the window is moved on, given in any arbitraryDuration
.initialLowerBound
- ThisMeasure
indicates 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, aMetricDescription
of must be specified.moveOnStrategy
- TheISlidingWindowMoveOnStrategy
instance 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
acceptedMetrics
ormoveOnStrategy
isnull
-
-
Method Details
-
onWindowFullEvent
protected final void onWindowFullEvent()This method is invoked once the sliding window is full.
All attachedISlidingWindowListener
are 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
- TheMeasuringValue
instance to add.- Throws:
IllegalArgumentException
- If the given measurement isnull
or 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
- TheMeasuringValue
to be added to the window data.- Throws:
IllegalArgumentException
- If the given measurement isnull
or 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
- TheMeasurement
to 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
MetricDescription
denoting 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:
true
if the metric is a base metric, otherwisefalse
.- See Also:
-
getCurrentLowerBound
Gets the current lower (i.e., left) bound of the window.- Returns:
- A
Measure
denoting the current upper bound. - See Also:
-
getCurrentUpperBound
Gets the current upper bound of the window.- Returns:
- A
Measure
denoting 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
Measure
denoting 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
Measure
denoting 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
Measure
denoting 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 aISlidingWindowListener
instance to this window.
Most commonly, the given listener is aSlidingWindowAggregator
.- Specified by:
addObserver
in interfaceorg.palladiosimulator.commons.designpatterns.IAbstractObservable<ISlidingWindowListener>
- Overrides:
addObserver
in classorg.palladiosimulator.commons.designpatterns.AbstractObservable<ISlidingWindowListener>
- Parameters:
arg0
- The listener to attach.- Throws:
IllegalArgumentException
- If the given listener isnull
or 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
ISlidingWindowListener
s.
-