T
- type of tuples in the windowK
- type of the window's keyL
- type of the list used to contain tuples.public interface Window<T,K,L extends java.util.List<T>>
Window
is partitioned by keys obtained
from tuples using a key function. Each tuple is
inserted into a partition containing all tuples
with the same key (using equals()
).
Each partition independently maintains the subset of
tuples defined by the windows policies.
An unpartitioned is created by using a key function that
returns a constant, to force all tuples to be inserted
into a single partition. A convenience function
unpartitioned()
is
provided that returns zero as the fixed key.
The window's policies are flexible to allow any definition of what tuples each partition will contain, and how the partition is processed.
Modifier and Type | Method and Description |
---|---|
BiConsumer<Partition<T,K,L>,T> |
getContentsPolicy()
Returns the contents policy of the window.
|
Consumer<Partition<T,K,L>> |
getEvictDeterminer()
Returns the window's eviction determiner.
|
BiFunction<Partition<T,K,L>,T,java.lang.Boolean> |
getInsertionPolicy()
Returns the insertion policy of the window.
|
Function<T,K> |
getKeyFunction()
Returns the keyFunction of the window
|
BiConsumer<java.util.List<T>,K> |
getPartitionProcessor()
Returns the partition processor associated with the window.
|
java.util.Map<K,Partition<T,K,L>> |
getPartitions()
Retrieves the partitions in the window.
|
java.util.concurrent.ScheduledExecutorService |
getScheduledExecutorService()
Returns the ScheduledExecutorService associated with the window.
|
BiConsumer<Partition<T,K,L>,T> |
getTriggerPolicy()
Returns the window's trigger policy.
|
boolean |
insert(T tuple)
Attempts to insert the tuple into its partition.
|
void |
registerPartitionProcessor(BiConsumer<java.util.List<T>,K> windowProcessor)
Register a WindowProcessor.
|
void |
registerScheduledExecutorService(java.util.concurrent.ScheduledExecutorService ses)
Register a ScheduledExecutorService.
|
boolean insert(T tuple)
K key = getKeyFunction().apply(tuple)
to obtain the partition key.key
creating an empty partition if one did not exist for key
. getInsertionPolicy().apply(partition, tuple)
. If it returns false then return false from this method,
otherwise continue.getContentsPolicy().apply(partition, tuple)
.
This is a pre-insertion action that allows any action. Some policies may request room to be made for
the insertion by calling evict()
which will result in a call to the evict determiner.tuple
to the contents of the partition.getTriggerPolicy().apply(partition, tuple)
.
This is a post-insertion that action allows any action. A typical implementation is to call
partition.process()
to perform processing of the window.
tuple
- the tuple to insertvoid registerPartitionProcessor(BiConsumer<java.util.List<T>,K> windowProcessor)
windowProcessor
- function to process the windowvoid registerScheduledExecutorService(java.util.concurrent.ScheduledExecutorService ses)
ses
- the serviceBiFunction<Partition<T,K,L>,T,java.lang.Boolean> getInsertionPolicy()
BiConsumer<Partition<T,K,L>,T> getContentsPolicy()
BiConsumer<Partition<T,K,L>,T> getTriggerPolicy()
BiConsumer<java.util.List<T>,K> getPartitionProcessor()
java.util.concurrent.ScheduledExecutorService getScheduledExecutorService()
Consumer<Partition<T,K,L>> getEvictDeterminer()
Partition.evict()
result in
getEvictDeterminer().accept(partition)
being
called.
In some cases this may not result in tuples being
evicted from the partition.
An evict determiner evicts tuples from the partition
by removing them from the list returned by
Partition.getContents()
.
Function<T,K> getKeyFunction()
java.util.Map<K,Partition<T,K,L>> getPartitions()
Map<K, Partitions<U, K, ?>> partitions = window.getPartitions();
synchronized(partitions){
// operations with partition
}
Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641