christophd commented on code in PR #27440: URL: https://github.com/apache/camel/pull/27440#discussion_r4207359089
########## components/camel-openfeature/src/main/java/org/apache/camel/component/openfeature/OpenFeatureComponent.java: ########## @@ -0,0 +1,127 @@ +/* + * 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.openfeature; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import dev.openfeature.sdk.Client; +import dev.openfeature.sdk.FeatureProvider; +import dev.openfeature.sdk.OpenFeatureAPI; +import org.apache.camel.Endpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component("openfeature") +public class OpenFeatureComponent extends DefaultComponent { + + private static final Logger LOG = LoggerFactory.getLogger(OpenFeatureComponent.class); + + @Metadata + private OpenFeatureConfiguration configuration = new OpenFeatureConfiguration(); + + private volatile OpenFeatureAPI api; + private final Map<String, DomainBinding> domainBindings = new ConcurrentHashMap<>(); + + private static class DomainBinding { + final FeatureProvider provider; + final boolean owned; + int refCount; + + DomainBinding(FeatureProvider provider, boolean owned) { + this.provider = provider; + this.owned = owned; + this.refCount = 1; + } + } + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + OpenFeatureEndpoint endpoint = new OpenFeatureEndpoint(uri, this, remaining, configuration.copy()); + setProperties(endpoint, parameters); + return endpoint; + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + api = OpenFeatureAPI.createIsolated(); + } + + @Override + protected void doStop() throws Exception { + api = null; Review Comment: Fixed. `doStop()` now calls `api.shutdown()` on the isolated API before discarding it, which releases all provider registrations from the static registry. This prevents the `IllegalStateException` on re-registration. Allowing an application-provided `OpenFeatureAPI` (never shut down by Camel) is a good follow-up enhancement. _Claude Code on behalf of christophd_ -- 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]
