bbejeck commented on code in PR #21513: URL: https://github.com/apache/kafka/pull/21513#discussion_r2835029994
########## streams/src/main/java/org/apache/kafka/streams/state/internals/MeteredSessionStoreWithHeaders.java: ########## @@ -0,0 +1,318 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.streams.state.internals; + +import org.apache.kafka.common.header.internals.RecordHeaders; +import org.apache.kafka.common.serialization.Deserializer; +import org.apache.kafka.common.serialization.Serde; +import org.apache.kafka.common.serialization.Serializer; +import org.apache.kafka.common.utils.Bytes; +import org.apache.kafka.common.utils.Time; +import org.apache.kafka.streams.internals.ApiUtils; +import org.apache.kafka.streams.kstream.Windowed; +import org.apache.kafka.streams.kstream.internals.Change; +import org.apache.kafka.streams.kstream.internals.WrappingNullableUtils; +import org.apache.kafka.streams.processor.StateStore; +import org.apache.kafka.streams.processor.StateStoreContext; +import org.apache.kafka.streams.processor.internals.ProcessorContextUtils; +import org.apache.kafka.streams.state.AggregationWithHeaders; +import org.apache.kafka.streams.state.KeyValueIterator; +import org.apache.kafka.streams.state.SessionStore; +import org.apache.kafka.streams.state.SessionStoreWithHeaders; +import org.apache.kafka.streams.state.StateSerdes; + +import java.time.Instant; + +import static org.apache.kafka.streams.internals.ApiUtils.prepareMillisCheckFailMsgPrefix; + +public class MeteredSessionStoreWithHeaders<K, AGG> + extends MeteredSessionStore<K, AggregationWithHeaders<AGG>> + implements SessionStoreWithHeaders<K, AGG> { + + private final Serde<AGG> rawAggSerde; + private StateSerdes<K, AGG> serdes; + private AggregationWithHeadersSerializer<AGG> aggregationWithHeadersSerializer; + private AggregationWithHeadersDeserializer<AGG> aggregationWithHeadersDeserializer; + + MeteredSessionStoreWithHeaders(final SessionStore<Bytes, byte[]> inner, + final String metricsScope, + final Serde<K> keySerde, + final Serde<AGG> aggSerde, + final Time time) { + super(inner, metricsScope, keySerde, createAggregationWithHeadersSerde(aggSerde), time); + this.rawAggSerde = aggSerde; + } + + private static <AGG> Serde<AggregationWithHeaders<AGG>> createAggregationWithHeadersSerde(final Serde<AGG> aggSerde) { + return new Serde<AggregationWithHeaders<AGG>>() { + @Override + public Serializer<AggregationWithHeaders<AGG>> serializer() { + return new AggregationWithHeadersSerializer<>(aggSerde.serializer()); + } + + @Override + public Deserializer<AggregationWithHeaders<AGG>> deserializer() { + return new AggregationWithHeadersDeserializer<>(aggSerde.deserializer()); + } + }; + } + + @Override + public void init(final StateStoreContext stateStoreContext, final StateStore root) { + initStoreSerde(stateStoreContext); + super.init(stateStoreContext, root); + } + + private void initStoreSerde(final StateStoreContext context) { + final String storeName = name(); + final String changelogTopic = ProcessorContextUtils.changelogFor(context, storeName, Boolean.FALSE); + serdes = StoreSerdeInitializer.prepareStoreSerde( + context, storeName, changelogTopic, keySerde, rawAggSerde, WrappingNullableUtils::prepareValueSerde); + aggregationWithHeadersSerializer = new AggregationWithHeadersSerializer<>(serdes.valueSerde().serializer()); + aggregationWithHeadersDeserializer = new AggregationWithHeadersDeserializer<>(serdes.valueSerde().deserializer()); + } + + @SuppressWarnings("unchecked") + @Override + public boolean setFlushListener(final CacheFlushListener<Windowed<K>, AggregationWithHeaders<AGG>> listener, Review Comment: @frankvicky the `CacheFlushListener` is decalred final the other part there is within the generics definition. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
