java.lang.Object
com.espertech.esper.common.internal.collection.TimeWindow
All Implemented Interfaces:
Iterable

public final class TimeWindow extends Object implements Iterable
Container for events per time slot. The time is provided as long milliseconds by client classes. Events are for a specified timestamp and the implementation creates and adds the event to a slot for that timestamp. Events can be expired from the window via the expireEvents method when their timestamp is before (or less then) an expiry timestamp passed in. Expiry removes the event from the window. The window allows iteration through its contents.

It is assumed that the timestamp passed to the add method is ascending. The window is backed by a collection reflecting the timestamp order rather then any sorted map or linked hash map for performance reasons.

  • Constructor Details

    • TimeWindow

      public TimeWindow(boolean isSupportRemoveStream)
      Ctor.
      Parameters:
      isSupportRemoveStream - true to indicate the time window should support effective removal of events in the window based on the remove stream events received, or false to not accomodate removal at all
  • Method Details

    • adjust

      public void adjust(long delta)
      Adjust expiry dates.
      Parameters:
      delta - delta to adjust for
    • add

      public final void add(long timestamp, EventBean bean)
      Adds event to the time window for the specified timestamp.
      Parameters:
      timestamp - - the time slot for the event
      bean - - event to add
    • remove

      public final void remove(EventBean theEvent)
      Removes the event from the window, if remove stream handling is enabled.
      Parameters:
      theEvent - to remove
    • expireEvents

      public final ArrayDeque<EventBean> expireEvents(long expireBefore)
      Return and remove events in time-slots earlier (less) then the timestamp passed in, returning the list of events expired.
      Parameters:
      expireBefore - is the timestamp from which on to keep events in the window
      Returns:
      a list of events expired and removed from the window, or null if none expired
    • iterator

      public final Iterator<EventBean> iterator()
      Returns event iterator.
      Specified by:
      iterator in interface Iterable
      Returns:
      iterator over events currently in window
    • getOldestTimestamp

      public final Long getOldestTimestamp()
      Returns the oldest timestamp in the collection if there is at least one entry, else it returns null if the window is empty.
      Returns:
      null if empty, oldest timestamp if not empty
    • isEmpty

      public final boolean isEmpty()
      Returns true if the window is currently empty.
      Returns:
      true if empty, false if not
    • getReverseIndex

      public Map<EventBean,TimeWindowPair> getReverseIndex()
      Returns the reverse index, for testing purposes.
      Returns:
      reverse index
    • getWindow

      public ArrayDeque<TimeWindowPair> getWindow()
    • setWindow

      public void setWindow(ArrayDeque<TimeWindowPair> window, int size)
    • setReverseIndex

      public void setReverseIndex(Map<EventBean,TimeWindowPair> reverseIndex)
    • visitView

      public void visitView(ViewDataVisitor viewDataVisitor, DataWindowViewFactory viewFactory)