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 aSlidingWindowRecorder
.
Once the window is full, the window moves forward by a fixed increment and the collected measurements are propagated to all connectedISlidingWindowListener
s, e.g., certainSlidingWindowAggregator
s.
Additionally, each window instance has an attachedISlidingWindowMoveOnStrategy
that defines how the collected data (i.e., the measurements) is adjusted when the window moves forward.
-
-
Constructor Summary
Constructors Constructor Description 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.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
acceptsBaseMetric()
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 void
addMeasurementInternal(org.palladiosimulator.measurementframework.MeasuringValue newMeasurement)
This method adds the given measurement to the window data.void
addObserver(ISlidingWindowListener arg0)
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.void
flush()
Discards the data (i.e., the measurements) currently collected by this window.org.palladiosimulator.metricspec.MetricDescription
getAcceptedMetric()
Gets the metric this window accepts.List<ISlidingWindowListener>
getAttachedObservers()
Gets the currently attached observers.javax.measure.Measure<Double,javax.measure.quantity.Duration>
getCurrentLowerBound()
Gets the current lower (i.e., left) bound of the window.javax.measure.Measure<Double,javax.measure.quantity.Duration>
getCurrentUpperBound()
Gets the current upper bound of the window.javax.measure.Measure<Double,javax.measure.quantity.Duration>
getEffectiveWindowLength()
Gets the current, effective window length.javax.measure.Measure<Double,javax.measure.quantity.Duration>
getIncrement()
Gets the value this window's lower bound is incremented by once the window moves on.int
getNumberOfElements()
Gets the number of currently collected measurements.protected 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.boolean
isEmpty()
Indicates if there are currently measurements available.protected 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.
-
-
-
Constructor Detail
-
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(Measure, Measure, MetricDescription, ISlidingWindowMoveOnStrategy)
-
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 Detail
-
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:
getAcceptedMetric()
-
getCurrentLowerBound
public final javax.measure.Measure<Double,javax.measure.quantity.Duration> getCurrentLowerBound()
Gets the current lower (i.e., left) bound of the window.- Returns:
- A
Measure
denoting the current upper bound. - See Also:
getEffectiveWindowLength()
,getCurrentUpperBound()
-
getCurrentUpperBound
public javax.measure.Measure<Double,javax.measure.quantity.Duration> 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()
,getCurrentUpperBound()
-
getEffectiveWindowLength
public javax.measure.Measure<Double,javax.measure.quantity.Duration> 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:
getCurrentUpperBound()
-
getIncrement
public final javax.measure.Measure<Double,javax.measure.quantity.Duration> 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:
SlidingWindow(Measure, MetricDescription, ISlidingWindowMoveOnStrategy)
,SlidingWindow(Measure, Measure, MetricDescription, ISlidingWindowMoveOnStrategy)
-
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
public final void addObserver(ISlidingWindowListener arg0)
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:
ISlidingWindowListener.getExpectedWindowDataMetric()
-
getAttachedObservers
public final List<ISlidingWindowListener> getAttachedObservers()
Gets the currently attached observers.- Returns:
- An unmodifiable list containing the attached
ISlidingWindowListener
s.
-
-