You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "orpiske (via GitHub)" <gi...@apache.org> on 2023/02/23 10:10:38 UTC

[GitHub] [camel] orpiske opened a new pull request, #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

orpiske opened a new pull request, #9400:
URL: https://github.com/apache/camel/pull/9400

   - replace ExtendedCamelContext inheritance with delegation
   - adjust the code to avoid casts to serveral context types (as they trigger the type check scalability issue)
   
   Note: 
   
   1. This is a very big change, so I'll put some comments on parts that may need attention and/or further review. 
   2. All tests are passing on my own CI
   3. If accepted, this enables a set of performance fixes that I'll share soon
   
   
   # Description
   
   <!--
   - Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   -->
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--  
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I formatted the code using `mvn -Pformat,fastinstall install && mvn -Psourcecheck`
   
   <!-- 
   You can run the aforementioned command in your module so that the build auto-formats your code and the source check verifies that is complies with our coding style. This will also be verified as part of the checks and your PR may be rejected if the checkstyle does not pass.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske merged pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske merged PR #9400:
URL: https://github.com/apache/camel/pull/9400


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #9400:
URL: https://github.com/apache/camel/pull/9400#discussion_r1115472629


##########
core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java:
##########
@@ -0,0 +1,1156 @@
+/*
+ * 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.impl.engine;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Endpoint;
+import org.apache.camel.ErrorHandlerFactory;
+import org.apache.camel.ExchangeConstantProvider;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.Processor;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.Route;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.Service;
+import org.apache.camel.catalog.RuntimeCamelCatalog;
+import org.apache.camel.console.DevConsoleResolver;
+import org.apache.camel.health.HealthCheckResolver;
+import org.apache.camel.spi.AnnotationBasedProcessorFactory;
+import org.apache.camel.spi.AsyncProcessorAwaitManager;
+import org.apache.camel.spi.BeanIntrospection;
+import org.apache.camel.spi.BeanProcessorFactory;
+import org.apache.camel.spi.BeanProxyFactory;
+import org.apache.camel.spi.BootstrapCloseable;
+import org.apache.camel.spi.CamelBeanPostProcessor;
+import org.apache.camel.spi.CamelDependencyInjectionAnnotationFactory;
+import org.apache.camel.spi.CliConnectorFactory;
+import org.apache.camel.spi.ComponentNameResolver;
+import org.apache.camel.spi.ComponentResolver;
+import org.apache.camel.spi.ConfigurerResolver;
+import org.apache.camel.spi.DataFormatResolver;
+import org.apache.camel.spi.Debugger;
+import org.apache.camel.spi.DebuggerFactory;
+import org.apache.camel.spi.DeferServiceFactory;
+import org.apache.camel.spi.EndpointStrategy;
+import org.apache.camel.spi.EndpointUriFactory;
+import org.apache.camel.spi.EventNotifier;
+import org.apache.camel.spi.ExchangeFactory;
+import org.apache.camel.spi.ExchangeFactoryManager;
+import org.apache.camel.spi.FactoryFinder;
+import org.apache.camel.spi.FactoryFinderResolver;
+import org.apache.camel.spi.HeadersMapFactory;
+import org.apache.camel.spi.InterceptEndpointFactory;
+import org.apache.camel.spi.InterceptStrategy;
+import org.apache.camel.spi.InternalProcessorFactory;
+import org.apache.camel.spi.LanguageResolver;
+import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.LogListener;
+import org.apache.camel.spi.ManagementMBeanAssembler;
+import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.spi.ManagementStrategyFactory;
+import org.apache.camel.spi.ModelJAXBContextFactory;
+import org.apache.camel.spi.ModelToXMLDumper;
+import org.apache.camel.spi.ModelineFactory;
+import org.apache.camel.spi.NodeIdFactory;
+import org.apache.camel.spi.NormalizedEndpointUri;
+import org.apache.camel.spi.PackageScanClassResolver;
+import org.apache.camel.spi.PackageScanResourceResolver;
+import org.apache.camel.spi.PeriodTaskResolver;
+import org.apache.camel.spi.PeriodTaskScheduler;
+import org.apache.camel.spi.ProcessorExchangeFactory;
+import org.apache.camel.spi.ProcessorFactory;
+import org.apache.camel.spi.PropertiesComponent;
+import org.apache.camel.spi.ReactiveExecutor;
+import org.apache.camel.spi.Registry;
+import org.apache.camel.spi.ResourceLoader;
+import org.apache.camel.spi.RestBindingJaxbDataFormatFactory;
+import org.apache.camel.spi.RouteController;
+import org.apache.camel.spi.RouteFactory;
+import org.apache.camel.spi.RouteStartupOrder;
+import org.apache.camel.spi.RoutesLoader;
+import org.apache.camel.spi.StartupStepRecorder;
+import org.apache.camel.spi.UnitOfWorkFactory;
+import org.apache.camel.spi.UriFactoryResolver;
+import org.apache.camel.support.EndpointHelper;
+import org.apache.camel.support.NormalizedUri;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class DefaultCamelContextExtension implements ExtendedCamelContext {
+    private static final Logger LOG = LoggerFactory.getLogger(DefaultCamelContextExtension.class);
+    
+    private final AbstractCamelContext camelContext;
+    private final ThreadLocal<Boolean> isSetupRoutes = new ThreadLocal<>();
+    private List<InterceptStrategy> interceptStrategies = new ArrayList<>();
+    private final Map<String, FactoryFinder> factories = new ConcurrentHashMap<>();
+    private Set<LogListener> logListeners;
+    private volatile String description;
+    @Deprecated
+    private ErrorHandlerFactory errorHandlerFactory;
+    private String basePackageScan;
+    private boolean lightweight;
+
+
+    public DefaultCamelContextExtension(AbstractCamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public byte getStatusPhase() {
+        return camelContext.getStatusPhase();
+    }
+
+    @Override
+    public String getName() {
+        return camelContext.getNameStrategy().getName();
+    }
+
+    @Override
+    public void setName(String name) {
+        // use an explicit name strategy since an explicit name was provided to be used
+        camelContext.setNameStrategy(new ExplicitCamelContextNameStrategy(name));
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public Endpoint hasEndpoint(NormalizedEndpointUri uri) {
+        if (camelContext.getEndpointRegistry().isEmpty()) {
+            return null;
+        }
+        return camelContext.getEndpointRegistry().get(uri);
+    }
+
+    @Override
+    public NormalizedEndpointUri normalizeUri(String uri) {
+        try {
+            uri = EndpointHelper.resolveEndpointUriPropertyPlaceholders(camelContext, uri);
+            return NormalizedUri.newNormalizedUri(uri, false);
+        } catch (ResolveEndpointFailedException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new ResolveEndpointFailedException(uri, e);
+        }
+    }
+
+    @Override
+    public Endpoint getEndpoint(NormalizedEndpointUri uri) {
+        return camelContext.doGetEndpoint(uri.getUri(), null, true, false);
+    }
+
+    @Override
+    public Endpoint getPrototypeEndpoint(String uri) {
+        return camelContext.doGetEndpoint(uri, null, false, true);
+    }
+
+    @Override
+    public Endpoint getPrototypeEndpoint(NormalizedEndpointUri uri) {
+        return camelContext.doGetEndpoint(uri.getUri(), null, true, true);
+    }
+
+    @Override
+    public Endpoint getEndpoint(NormalizedEndpointUri uri, Map<String, Object> parameters) {
+        return camelContext.doGetEndpoint(uri.getUri(), parameters, true, false);
+    }
+
+    @Override
+    public void registerEndpointCallback(EndpointStrategy strategy) {
+        if (!camelContext.getEndpointStrategies().contains(strategy)) {
+            // let it be invoked for already registered endpoints so it can
+            // catch-up.
+            camelContext.getEndpointStrategies().add(strategy);
+            for (Endpoint endpoint : camelContext.getEndpoints()) {
+                Endpoint newEndpoint = strategy.registerEndpoint(endpoint.getEndpointUri(), endpoint);
+                if (newEndpoint != null) {
+                    // put will replace existing endpoint with the new endpoint
+                    camelContext.getEndpointRegistry().put(camelContext.getEndpointKey(endpoint.getEndpointUri()), newEndpoint);
+                }
+            }
+        }
+    }
+
+    @Override
+    public List<RouteStartupOrder> getRouteStartupOrder() {
+        return camelContext.getRouteStartupOrder();
+    }
+
+    @Override
+    public boolean isSetupRoutes() {
+        Boolean answer = isSetupRoutes.get();
+        return answer != null && answer;
+    }
+
+    @Override
+    public void addBootstrap(BootstrapCloseable bootstrap) {
+        camelContext.bootstraps.add(bootstrap);
+    }
+
+    @Override
+    public List<Service> getServices() {
+        return Collections.unmodifiableList(camelContext.servicesToStop);
+    }
+
+    @Override
+    public String resolvePropertyPlaceholders(String text, boolean keepUnresolvedOptional) {
+        if (text != null && text.contains(PropertiesComponent.PREFIX_TOKEN)) {
+            // the parser will throw exception if property key was not found
+            String answer = camelContext.getPropertiesComponent().parseUri(text, keepUnresolvedOptional);
+            LOG.debug("Resolved text: {} -> {}", text, answer);
+            return answer;
+        }
+        // is the value a known field (currently we only support
+        // constants from Exchange.class)
+        if (text != null && text.startsWith("Exchange.")) {
+            String field = StringHelper.after(text, "Exchange.");
+            String constant = ExchangeConstantProvider.lookup(field);
+            if (constant != null) {
+                LOG.debug("Resolved constant: {} -> {}", text, constant);
+                return constant;
+            } else {
+                throw new IllegalArgumentException("Constant field with name: " + field + " not found on Exchange.class");
+            }
+        }
+
+        // return original text as is
+        return text;
+    }
+
+    @Override
+    public CamelBeanPostProcessor getBeanPostProcessor() {
+        if (camelContext.beanPostProcessor == null) {
+            synchronized (camelContext.lock) {
+                if (camelContext.beanPostProcessor == null) {
+                    setBeanPostProcessor(camelContext.createBeanPostProcessor());
+                }
+            }
+        }
+        return camelContext.beanPostProcessor;

Review Comment:
   You'll see this pattern of accessing internal `AbstractCamelContext` member variables in this class. Because this is a big change, I am doing in steps. This will be cleaned up in future PRs.  



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #9400:
URL: https://github.com/apache/camel/pull/9400#discussion_r1115476227


##########
core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java:
##########
@@ -33,6 +33,30 @@
  * <b>META-INF/services/org/apache/camel/configurer/</b>.
  */
 public class DefaultConfigurerResolver implements ConfigurerResolver {
+    /**
+     * This is a special container for the CamelContext because, with Camel 4, we split the CamelContext and the former
+     * ExtendedCamelContext. This holds them in a single configuration, directing the target appropriately
+     */
+    public static class ContextConfigurer implements PropertyConfigurer {
+        private final PropertyConfigurer contextConfigurer;
+        private final PropertyConfigurer extensionConfigurer;
+
+        public ContextConfigurer(PropertyConfigurer contextConfigurer, PropertyConfigurer extensionConfigurer) {
+            this.contextConfigurer = contextConfigurer;
+            this.extensionConfigurer = extensionConfigurer;
+        }
+
+        @Override
+        public boolean configure(CamelContext camelContext, Object target, String name, Object value, boolean ignoreCase) {
+            if (target instanceof CamelContext contextTarget) {
+                if (!contextConfigurer.configure(camelContext, contextTarget, name, value, ignoreCase)) {
+                    return extensionConfigurer.configure(camelContext, contextTarget.getCamelContextExtension(), name, value, ignoreCase);
+                }
+            }
+
+            return false;
+        }
+    }

Review Comment:
   This part review may need some further review. Because I split the `ExtendedCamelContext` from the `CamelContext`, it means it could impact usage of the `*Configurer` classes (and many tests did fail because of that). So, the PR brings this wrapper class that glues the configurer for the `ExtendedCamelContext` from the `CamelContext` so that they act as before. 



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9400:
URL: https://github.com/apache/camel/pull/9400#issuecomment-1441559533

   :leftwards_arrow_with_hook: There are either **too many** changes to be tested in this PR or the code **needs be rebased**: (63 components likely to be affected)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #9400:
URL: https://github.com/apache/camel/pull/9400#discussion_r1115480254


##########
core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java:
##########
@@ -631,10 +631,8 @@ public void setUuidGenerator(UuidGenerator uuidGenerator) {
     }
 
     @Override
-    public <T extends CamelContext> T adapt(Class<T> type) {
-        if (type.isInstance(this)) {
-            return type.cast(this);
-        }
+    public ExtendedCamelContext getCamelContextExtension() {
+        // TODO: implement
         throw new UnsupportedOperationException();

Review Comment:
   Tracked on: https://issues.apache.org/jira/browse/CAMEL-19086
   



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on a diff in pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #9400:
URL: https://github.com/apache/camel/pull/9400#discussion_r1115477582


##########
core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultPackageScanResourceResolver.java:
##########
@@ -97,7 +97,7 @@ protected void findInFileSystem(
             String subPattern)
             throws Exception {
 
-        final ExtendedCamelContext ecc = getCamelContext().adapt(ExtendedCamelContext.class);
+        final ExtendedCamelContext ecc = getCamelContext().getCamelContextExtension();

Review Comment:
   Besides the core changes, this is likely what you can see in many of the component changes.



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9400:
URL: https://github.com/apache/camel/pull/9400#issuecomment-1441494599

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :warning: Please note that the changes on this PR may be **tested automatically**. 
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9400:
URL: https://github.com/apache/camel/pull/9400#issuecomment-1445128709

   :leftwards_arrow_with_hook: There are either **too many** changes to be tested in this PR or the code **needs be rebased**: (63 components likely to be affected)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on PR #9400:
URL: https://github.com/apache/camel/pull/9400#issuecomment-1445117727

   I'm resolving the conflicts and then it will be ready for merge. 


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9400:
URL: https://github.com/apache/camel/pull/9400#issuecomment-1442220287

   :leftwards_arrow_with_hook: There are either **too many** changes to be tested in this PR or the code **needs be rebased**: (63 components likely to be affected)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] orpiske commented on pull request #9400: CAMEL-15105: decouple the ExtendedCamelContext from CamelContext

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on PR #9400:
URL: https://github.com/apache/camel/pull/9400#issuecomment-1441498853

   The PR is "ready" (pending comments/reviews), but marking as a draft to prevent it from being merged from some time. 


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org