This is an automated email from the ASF dual-hosted git repository.

jiriondrusek pushed a commit to branch camel-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/camel-main by this push:
     new 42744911e7 Woarkaround for native failure with serviceLoader
42744911e7 is described below

commit 42744911e7646b6a4a8a6c019f057b91f8b4ddb3
Author: Jiri Ondrusek <[email protected]>
AuthorDate: Fri Oct 3 11:45:57 2025 +0200

    Woarkaround for native failure with serviceLoader
---
 .../camel/quarkus/core/FastCamelContext.java       |  6 ++
 .../core/QuarkusContextServiceLoaderPlugin.java    | 87 ++++++++++++++++++++++
 2 files changed, 93 insertions(+)

diff --git 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java
 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java
index 2380ac62be..c9f69d368c 100644
--- 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java
+++ 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java
@@ -36,6 +36,7 @@ import org.apache.camel.spi.CamelBeanPostProcessor;
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.ComponentNameResolver;
 import org.apache.camel.spi.ComponentResolver;
+import org.apache.camel.spi.ContextServiceLoaderPluginResolver;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.FactoryFinderResolver;
 import org.apache.camel.spi.Language;
@@ -156,6 +157,11 @@ public class FastCamelContext extends DefaultCamelContext 
implements CatalogCame
         return null;
     }
 
+    @Override
+    protected ContextServiceLoaderPluginResolver 
createContextServiceLoaderPlugin() {
+        return new QuarkusContextServiceLoaderPlugin();
+    }
+
     @Override
     protected ClassResolver createClassResolver() {
         return new 
CamelQuarkusClassResolver(Objects.requireNonNull(getApplicationContextClassLoader(),
diff --git 
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/QuarkusContextServiceLoaderPlugin.java
 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/QuarkusContextServiceLoaderPlugin.java
new file mode 100644
index 0000000000..16465720eb
--- /dev/null
+++ 
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/QuarkusContextServiceLoaderPlugin.java
@@ -0,0 +1,87 @@
+/*
+ * 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.quarkus.core;
+
+import java.util.ServiceLoader;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ContextServiceLoaderPluginResolver;
+import org.apache.camel.spi.ContextServicePlugin;
+import org.apache.camel.support.service.ServiceSupport;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class QuarkusContextServiceLoaderPlugin extends ServiceSupport 
implements ContextServiceLoaderPluginResolver {
+    private static final Logger LOG = 
LoggerFactory.getLogger(QuarkusContextServiceLoaderPlugin.class);
+
+    private CamelContext camelContext;
+
+    /**
+     * Discovers and loads all {@link ContextServicePlugin} implementations 
found on the classpath.
+     * <p>
+     * This method is called during service startup and uses {@link 
ServiceLoader} to automatically discover plugin
+     * implementations. Each discovered plugin's {@code load} method is 
invoked with the current CamelContext, allowing
+     * plugins to perform their initialization logic.
+     * <p>
+     * The plugins are loaded in the order they are discovered by the 
ServiceLoader, which may vary between JVM
+     * implementations and is generally not guaranteed to be deterministic.
+     *
+     * @throws Exception if any plugin fails to load or throws an exception 
during initialization
+     */
+    @Override
+    protected void doStart() throws Exception {
+        ServiceLoader<ContextServicePlugin> contextServicePlugins = 
ServiceLoader.load(ContextServicePlugin.class,
+                camelContext.getApplicationContextClassLoader());
+        for (ContextServicePlugin plugin : contextServicePlugins) {
+            try {
+                plugin.load(camelContext);
+            } catch (Exception e) {
+                LOG.warn(
+                        "Loading of plugin {} failed, however the exception 
will be ignored so others plugins can be initialized. Reason: {}",
+                        plugin.getClass().getName(), e.getMessage(), e);
+            }
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        ServiceLoader<ContextServicePlugin> contextServicePlugins = 
ServiceLoader.load(ContextServicePlugin.class,
+                camelContext.getApplicationContextClassLoader());
+        if (contextServicePlugins != null) {
+            for (ContextServicePlugin plugin : contextServicePlugins) {
+                try {
+                    plugin.unload(camelContext);
+                } catch (Exception e) {
+                    LOG.warn(
+                            "Unloading of plugin {} failed, however the 
exception will be ignored so shutdown can continue. Reason: {}",
+                            plugin.getClass().getName(), e.getMessage(), e);
+                }
+            }
+        }
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+}
\ No newline at end of file

Reply via email to