Search in sources :

Example 1 with KStreamWindowAggregate

use of org.apache.kafka.streams.kstream.internals.KStreamWindowAggregate in project kafka by apache.

the class GraphGraceSearchUtil method extractGracePeriod.

@SuppressWarnings("rawtypes")
private static Long extractGracePeriod(final GraphNode node) {
    if (node instanceof StatefulProcessorNode) {
        final ProcessorSupplier processorSupplier = ((StatefulProcessorNode) node).processorParameters().processorSupplier();
        if (processorSupplier instanceof KStreamWindowAggregate) {
            final KStreamWindowAggregate kStreamWindowAggregate = (KStreamWindowAggregate) processorSupplier;
            final Windows windows = kStreamWindowAggregate.windows();
            return windows.gracePeriodMs();
        } else if (processorSupplier instanceof KStreamSessionWindowAggregate) {
            final KStreamSessionWindowAggregate kStreamSessionWindowAggregate = (KStreamSessionWindowAggregate) processorSupplier;
            final SessionWindows windows = kStreamSessionWindowAggregate.windows();
            return windows.gracePeriodMs() + windows.inactivityGap();
        } else if (processorSupplier instanceof KStreamSlidingWindowAggregate) {
            final KStreamSlidingWindowAggregate kStreamSlidingWindowAggregate = (KStreamSlidingWindowAggregate) processorSupplier;
            final SlidingWindows windows = kStreamSlidingWindowAggregate.windows();
            return windows.gracePeriodMs();
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : SessionWindows(org.apache.kafka.streams.kstream.SessionWindows) ProcessorSupplier(org.apache.kafka.streams.processor.api.ProcessorSupplier) SessionWindows(org.apache.kafka.streams.kstream.SessionWindows) Windows(org.apache.kafka.streams.kstream.Windows) SlidingWindows(org.apache.kafka.streams.kstream.SlidingWindows) KStreamSessionWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate) KStreamWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamWindowAggregate) KStreamSlidingWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamSlidingWindowAggregate) SlidingWindows(org.apache.kafka.streams.kstream.SlidingWindows)

Example 2 with KStreamWindowAggregate

use of org.apache.kafka.streams.kstream.internals.KStreamWindowAggregate in project kafka by apache.

the class GraphGraceSearchUtilTest method shouldExtractGraceFromKStreamWindowAggregateNode.

@Test
public void shouldExtractGraceFromKStreamWindowAggregateNode() {
    final TimeWindows windows = TimeWindows.ofSizeAndGrace(ofMillis(10L), ofMillis(1234L));
    final StatefulProcessorNode<String, Long> node = new StatefulProcessorNode<>("asdf", new ProcessorParameters<>(new KStreamWindowAggregate<String, Long, Integer, TimeWindow>(windows, "asdf", null, null), "asdf"), (StoreBuilder<?>) null);
    final long extracted = GraphGraceSearchUtil.findAndVerifyWindowGrace(node);
    assertThat(extracted, is(windows.gracePeriodMs()));
}
Also used : TimeWindows(org.apache.kafka.streams.kstream.TimeWindows) KStreamWindowAggregate(org.apache.kafka.streams.kstream.internals.KStreamWindowAggregate) Test(org.junit.Test)

Aggregations

KStreamWindowAggregate (org.apache.kafka.streams.kstream.internals.KStreamWindowAggregate)2 SessionWindows (org.apache.kafka.streams.kstream.SessionWindows)1 SlidingWindows (org.apache.kafka.streams.kstream.SlidingWindows)1 TimeWindows (org.apache.kafka.streams.kstream.TimeWindows)1 Windows (org.apache.kafka.streams.kstream.Windows)1 KStreamSessionWindowAggregate (org.apache.kafka.streams.kstream.internals.KStreamSessionWindowAggregate)1 KStreamSlidingWindowAggregate (org.apache.kafka.streams.kstream.internals.KStreamSlidingWindowAggregate)1 ProcessorSupplier (org.apache.kafka.streams.processor.api.ProcessorSupplier)1 Test (org.junit.Test)1