Croway commented on code in PR #28086: URL: https://github.com/apache/camel/pull/28086#discussion_r4311775556
########## components/camel-state-store/camel-state-store/src/main/java/org/apache/camel/component/statestore/StateStoreBackendFactory.java: ########## @@ -0,0 +1,39 @@ +/* + * 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.camel.component.statestore; + +import org.apache.camel.spi.KeyValueRepository; + +/** + * Creates the {@link KeyValueRepository} backend for a given state store name. + * <p/> Review Comment: Fixed in 027248a63110, thanks. _Claude Code on behalf of Federico Mariani_ ########## components/camel-state-store/camel-state-store/src/main/java/org/apache/camel/component/statestore/StateStoreBackendFactory.java: ########## @@ -0,0 +1,39 @@ +/* + * 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.camel.component.statestore; + +import org.apache.camel.spi.KeyValueRepository; + +/** + * Creates the {@link KeyValueRepository} backend for a given state store name. + * <p/> + * Use this when each store name should map to its own backend instance, for example a separate cache per store. The + * returned backend is owned by the {@link StateStoreComponent}, which starts and stops it. + * + * @since 4.24 + */ +@FunctionalInterface +public interface StateStoreBackendFactory { + + /** + * Creates the backend for the given store name. + * + * @param storeName the name of the state store, as used in the endpoint URI + * @return the backend for the store, or <tt>null</tt> to fall back to the default backend resolution + */ Review Comment: Fixed in 027248a63110 (`{@code null}`). _Claude Code on behalf of Federico Mariani_ ########## components/camel-state-store/camel-state-store/src/main/java/org/apache/camel/component/statestore/StateStoreBackendFactory.java: ########## @@ -0,0 +1,39 @@ +/* + * 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.camel.component.statestore; + +import org.apache.camel.spi.KeyValueRepository; + +/** + * Creates the {@link KeyValueRepository} backend for a given state store name. + * <p/> + * Use this when each store name should map to its own backend instance, for example a separate cache per store. The + * returned backend is owned by the {@link StateStoreComponent}, which starts and stops it. + * + * @since 4.24 + */ +@FunctionalInterface +public interface StateStoreBackendFactory { + + /** + * Creates the backend for the given store name. + * + * @param storeName the name of the state store, as used in the endpoint URI + * @return the backend for the store, or <tt>null</tt> to fall back to the default backend resolution Review Comment: Fixed in 027248a63110 (`{@code null}`). _Claude Code on behalf of Federico Mariani_ ########## components/camel-state-store/camel-state-store/src/main/java/org/apache/camel/component/statestore/StateStoreComponent.java: ########## @@ -68,9 +74,15 @@ KeyValueRepository getOrCreateBackend(String storeName, KeyValueRepository expli return explicitBackend; } return backends.computeIfAbsent(storeName, k -> { + KeyValueRepository backend = backendFactory != null ? backendFactory.createBackend(storeName) : null; Review Comment: Good point, added in 027248a63110. One change from the suggestion: the check isn't in `doInit()`. `AbstractCamelContext` initializes the component (or starts it, when the context is already running) *before* `onComponentAdd` runs `DefaultAutowiredLifecycleStrategy`, so in `doInit()`/`doStart()` `backendFactory` can still be `null` even when it will be autowired or set by a customizer right after. The check now runs lazily, once, on the first backend resolution in `getOrCreateBackend`, which always happens after autowiring. `StateStoreBackendFactoryAmbiguousTest` now also asserts the WARN, and the docs NOTE no longer says "silently". _Claude Code on behalf of Federico Mariani_ -- 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]
