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 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.
See Also:
  • 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 the SlidingWindow class with the given parameters.
      Parameters:
      windowLength - The length of the window, given in any arbitrary Duration. Additionally, this measure also denotes the window increment.
      acceptedMetrics - As each window only accepts measurements that adhere to a certain metric, a MetricDescription of must be specified.
      moveOnStrategy - The ISlidingWindowMoveOnStrategy 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 or moveOnStrategy is null
      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 the SlidingWindow class with the given parameters.
      Parameters:
      windowLength - The length of the window, given in any arbitrary Duration.
      increment - This Measure indicates the increment by what the window is moved on, given in any arbitrary Duration.
      acceptedMetrics - As each window only accepts measurements that adhere to a certain metric, a MetricDescription of must be specified.
      moveOnStrategy - The ISlidingWindowMoveOnStrategy 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 or moveOnStrategy is null
    • 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 the SlidingWindow class with the given parameters.
      Parameters:
      windowLength - The length of the window, given in any arbitrary Duration.
      increment - This Measure indicates the increment by what the window is moved on, given in any arbitrary Duration.
      initialLowerBound - This Measure indicates the lower bound value at which the algorithm starts aggregating, given in any arbitrary Duration.
      acceptedMetrics - As each window only accepts measurements that adhere to a certain metric, a MetricDescription of must be specified.
      moveOnStrategy - The ISlidingWindowMoveOnStrategy 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 or moveOnStrategy is null
  • Method Details

    • onWindowFullEvent

      protected final void onWindowFullEvent()
      This method is invoked once the sliding window is full.
      All attached ISlidingWindowListener 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 - The MeasuringValue instance to add.
      Throws:
      IllegalArgumentException - If the given measurement is null 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 - The MeasuringValue to be added to the window data.
      Throws:
      IllegalArgumentException - If the given measurement is null 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 override addMeasurement(MeasuringValue), implementations should take care to call checkAddMeasurementPrerequisites(MeasuringValue) beforehand to ensure uncorrupt window data.
      Parameters:
      newMeasurement - The Measurement 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 a BaseMetricDescription. The same result is obtained by calling getAcceptedMetric() and then doing a type check.
      Returns:
      true if the metric is a base metric, otherwise false.
      See Also:
    • 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:
    • 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 in SlidingWindow(Measure, MetricDescription, ISlidingWindowMoveOnStrategy) or SlidingWindow(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

      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 in SlidingWindow(Measure, MetricDescription, ISlidingWindowMoveOnStrategy) or SlidingWindow(Measure, Measure, MetricDescription, ISlidingWindowMoveOnStrategy) .
      Returns:
      A Measure denoting the instantaneous effective window length.
      See Also:
    • 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:
    • isEmpty

      public final boolean isEmpty()
      Indicates if there are currently measurements available.
      Returns:
      false, if yes, otherwise true
    • 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 a ISlidingWindowListener instance to this window.
      Most commonly, the given listener is a SlidingWindowAggregator.
      Specified by:
      addObserver in interface org.palladiosimulator.commons.designpatterns.IAbstractObservable<ISlidingWindowListener>
      Overrides:
      addObserver in class org.palladiosimulator.commons.designpatterns.AbstractObservable<ISlidingWindowListener>
      Parameters:
      arg0 - The listener to attach.
      Throws:
      IllegalArgumentException - If the given listener is null or expects a metric other than this window's accepted one.
      See Also:
    • getAttachedObservers

      public final List<ISlidingWindowListener> getAttachedObservers()
      Gets the currently attached observers.
      Returns:
      An unmodifiable list containing the attached ISlidingWindowListeners.