agavra commented on code in PR #14659: URL: https://github.com/apache/kafka/pull/14659#discussion_r1378192463
########## streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreBuilderWrapper.java: ########## @@ -0,0 +1,119 @@ +/* + * 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.processor.internals; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.kafka.streams.processor.StateStore; +import org.apache.kafka.streams.state.StoreBuilder; +import org.apache.kafka.streams.state.internals.SessionStoreBuilder; +import org.apache.kafka.streams.state.internals.TimestampedWindowStoreBuilder; +import org.apache.kafka.streams.state.internals.VersionedKeyValueStoreBuilder; +import org.apache.kafka.streams.state.internals.WindowStoreBuilder; + +public class StoreBuilderWrapper<S extends StateStore> implements StoreFactory<S> { + + private final StoreBuilder<S> builder; + private final Set<String> users = new HashSet<>(); + + public StoreBuilderWrapper(final StoreBuilder<S> builder) { + this.builder = builder; + } + + @Override + public S build() { + return builder.build(); + } + + @Override + public long retentionPeriod() { + if (builder instanceof WindowStoreBuilder) { + return ((WindowStoreBuilder<?, ?>) builder).retentionPeriod(); + } else if (builder instanceof TimestampedWindowStoreBuilder) { + return ((TimestampedWindowStoreBuilder<?, ?>) builder).retentionPeriod(); + } else if (builder instanceof SessionStoreBuilder) { + return ((SessionStoreBuilder<?, ?>) builder).retentionPeriod(); + } else { + throw new IllegalStateException( + "retentionPeriod is not supported when not a window store"); + } + } + + @Override + public long historyRetention() { + if (builder instanceof VersionedKeyValueStoreBuilder) { + return ((VersionedKeyValueStoreBuilder<?, ?>) builder).historyRetention(); + } else { + throw new IllegalStateException( + "historyRetention is not supported when not a versioned store"); + } + } + + @Override + public Set<String> users() { + return users; + } + + @Override + public boolean loggingEnabled() { + return builder.loggingEnabled(); + } + + @Override + public String name() { + return builder.name(); + } + + @Override + public boolean isWindowStore() { + return builder instanceof WindowStoreBuilder + || builder instanceof TimestampedWindowStoreBuilder + || builder instanceof SessionStoreBuilder; + } + + @Override + public boolean isVersionedStore() { + return builder instanceof VersionedKeyValueStoreBuilder; + } + + // Apparently Java strips the generics from this method because we're using the raw type for builder, + // even though this method doesn't use builder's (missing) type parameter. Our usage seems obviously + // correct, though, hence the suppression. + @Override + public Map<String, String> logConfig() { + return builder.logConfig(); + } + + @Override + public StoreFactory<S> withCachingDisabled() { + builder.withCachingDisabled(); + return this; + } + + @Override + public StoreFactory<S> withLoggingDisabled() { + builder.withLoggingDisabled(); + return this; + } + + @Override + public boolean isCompatibleWith(final StoreFactory<?> storeFactory) { Review Comment: I'll add a comment. The plan is to add a separate `DelayedStoreFactory` which delays the creation of the `StoreBuilder` until `configure` is called. the `isCompatibleWith` method will check to make sure the inner components would generate the same store builder (e.g. the wrapped `StoreSuppliers` are identical) I'll just make that change and add it to this PR to show how it works end-to-end, but that will be a functionality change. EDIT: actually I can add it w/o changing functionality if I just ignore `configure()` -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org