W
- The type of Window
that this set is keeping track of.public class MergingWindowSet<W extends Window> extends Object
Windows
when using a MergingWindowAssigner
in a WindowOperator
.
When merging windows, we keep one of the original windows as the state window, i.e. the window
that is used as namespace to store the window elements. Elements from the state windows of merged
windows must be merged into this one state window. We keep a mapping from in-flight window to
state window that can be queried using getStateWindow(Window)
.
A new window can be added to the set of in-flight windows using addWindow(Window,
MergeFunction)
. This might merge other windows and the caller must react accordingly in the
MergingWindowSet.MergeFunction.merge(Object, Collection, Object, Collection)
and adjust the outside view
of windows and state.
Windows can be removed from the set of windows using retireWindow(Window)
.
Modifier and Type | Class and Description |
---|---|
static interface |
MergingWindowSet.MergeFunction<W>
Callback for
addWindow(Window, MergeFunction) . |
Constructor and Description |
---|
MergingWindowSet(MergingWindowAssigner<W> windowAssigner,
MapState<W,W> mapping)
Restores a
MergingWindowSet from the given state. |
Modifier and Type | Method and Description |
---|---|
W |
addWindow(W newWindow,
MergingWindowSet.MergeFunction<W> mergeFunction)
Adds a new
Window to the set of in-flight windows. |
W |
getStateWindow(W window)
Returns the state window for the given in-flight
Window . |
void |
initializeCache(Object key)
Set current key context of this window set.
|
void |
retireWindow(W window)
Removes the given window from the set of in-flight windows.
|
String |
toString() |
public MergingWindowSet(MergingWindowAssigner<W> windowAssigner, MapState<W,W> mapping)
MergingWindowSet
from the given state.public void initializeCache(Object key) throws Exception
Notes: initializeCache(Object)
must be called before addWindow(Window,
MergeFunction)
and retireWindow(Window)
key
- the current access keyException
public W getStateWindow(W window) throws Exception
Window
. The state window is the
Window
in which we keep the actual state of a given in-flight window. Windows might
expand but we keep to original state window for keeping the elements of the window to avoid
costly state juggling.window
- The window for which to get the state window.Exception
public void retireWindow(W window) throws Exception
window
- The Window
to remove.Exception
public W addWindow(W newWindow, MergingWindowSet.MergeFunction<W> mergeFunction) throws Exception
Window
to the set of in-flight windows. It might happen that this triggers
merging of previously in-flight windows. In that case, the provided MergingWindowSet.MergeFunction
is
called.
This returns the window that is the representative of the added window after adding. This can either be the new window itself, if no merge occurred, or the newly merged window. Adding an element to a window or calling trigger functions should only happen on the returned representative. This way, we never have to deal with a new window that is immediately swallowed up by another window.
If the new window is merged, the MergeFunction
callback arguments also don't
contain the new window as part of the list of merged windows.
newWindow
- The new Window
to add.mergeFunction
- The callback to be invoked in case a merge occurs.Window
that new new Window
ended up in. This can also be the new
Window
itself in case no merge occurred.Exception
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.