You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/10/14 14:44:12 UTC

[camel-k-runtime] 02/02: chore: quarkus fixes for camel-knative

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

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit a376ded50db67a1b93593c14073ad089440772db
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Oct 14 16:43:55 2019 +0200

    chore: quarkus fixes for camel-knative
---
 .../camel/component/knative/KnativeComponent.java  | 22 ++++++++++++++++++++--
 .../camel/component/knative/KnativeEndpoint.java   |  9 +++------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java b/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java
index 90064c4..5529485 100644
--- a/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java
+++ b/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java
@@ -34,9 +34,13 @@ import org.apache.camel.support.service.ServiceHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.PropertiesHelper;
 import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @Component("knative")
 public class KnativeComponent extends DefaultComponent {
+    private static final Logger LOGGER = LoggerFactory.getLogger(KnativeComponent.class);
+
     public static final String CONFIGURATION_ENV_VARIABLE = "CAMEL_KNATIVE_CONFIGURATION";
 
     private KnativeConfiguration configuration;
@@ -157,6 +161,8 @@ public class KnativeComponent extends DefaultComponent {
 
     @Override
     protected void doInit() throws Exception {
+        super.doInit();
+
         if (transport == null) {
             this.transport = getCamelContext().getRegistry().lookupByNameAndType(protocol.name(), KnativeTransport.class);
 
@@ -166,14 +172,24 @@ public class KnativeComponent extends DefaultComponent {
                     .getFactoryFinder(Knative.KNATIVE_TRANSPORT_RESOURCE_PATH)
                     .newInstance(protocol.name(), KnativeTransport.class)
                     .orElseThrow(() -> new RuntimeException("Error creating knative transport for protocol: " + protocol.name()));
+            }
+
+            if (this.transport instanceof CamelContextAware) {
+                CamelContextAware camelContextAware = (CamelContextAware)this.transport;
 
-                CamelContextAware.trySetCamelContext(transport, getCamelContext());
+                if (camelContextAware.getCamelContext() == null) {
+                    camelContextAware.setCamelContext(getCamelContext());
+                }
             }
         }
+
+        LOGGER.info("found knative transport: {} for protocol: {}", transport, protocol.name());
     }
 
     @Override
     protected void doStart() throws Exception {
+        super.doStart();
+
         if (this.transport != null && managedTransport) {
             ServiceHelper.startService(this.transport);
         }
@@ -181,6 +197,8 @@ public class KnativeComponent extends DefaultComponent {
 
     @Override
     protected void doStop() throws Exception {
+        super.doStop();
+
         if (this.transport != null && managedTransport) {
             ServiceHelper.stopService(this.transport);
         }
@@ -216,7 +234,7 @@ public class KnativeComponent extends DefaultComponent {
             conf.setServiceName(name);
         }
 
-        return new KnativeEndpoint(uri, this, Knative.Type.valueOf(type), name, this.transport, conf);
+        return new KnativeEndpoint(uri, this, Knative.Type.valueOf(type), name, conf);
     }
 
     // ************************
diff --git a/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeEndpoint.java b/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeEndpoint.java
index a71b954..09ae6f7 100644
--- a/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeEndpoint.java
+++ b/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeEndpoint.java
@@ -28,7 +28,6 @@ import org.apache.camel.component.knative.ce.CloudEventProcessor;
 import org.apache.camel.component.knative.ce.CloudEventProcessors;
 import org.apache.camel.component.knative.spi.Knative;
 import org.apache.camel.component.knative.spi.KnativeEnvironment;
-import org.apache.camel.component.knative.spi.KnativeTransport;
 import org.apache.camel.processor.Pipeline;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -52,15 +51,13 @@ public class KnativeEndpoint extends DefaultEndpoint {
     @UriParam
     private KnativeConfiguration configuration;
 
-    private final KnativeTransport transport;
     private final CloudEventProcessor cloudEvent;
 
-    public KnativeEndpoint(String uri, KnativeComponent component, Knative.Type type, String name, KnativeTransport transport, KnativeConfiguration configuration) {
+    public KnativeEndpoint(String uri, KnativeComponent component, Knative.Type type, String name, KnativeConfiguration configuration) {
         super(uri, component);
 
         this.type = type;
         this.name = name;
-        this.transport = transport;
         this.configuration = configuration;
         this.cloudEvent = CloudEventProcessors.fromSpecVersion(configuration.getCloudEventsSpecVersion());
     }
@@ -75,7 +72,7 @@ public class KnativeEndpoint extends DefaultEndpoint {
         final KnativeEnvironment.KnativeServiceDefinition service = lookupServiceDefinition(Knative.EndpointKind.sink);
         final Processor ceProcessor = cloudEvent.producer(this, service);
         final Processor ceConverter = new KnativeConversionProcessor(configuration.isJsonSerializationEnabled());
-        final Producer producer = transport.createProducer(this, service);
+        final Producer producer = getComponent().getTransport().createProducer(this, service);
 
         PropertyBindingSupport.build()
             .withCamelContext(getCamelContext())
@@ -92,7 +89,7 @@ public class KnativeEndpoint extends DefaultEndpoint {
         final KnativeEnvironment.KnativeServiceDefinition service = lookupServiceDefinition(Knative.EndpointKind.source);
         final Processor ceProcessor = cloudEvent.consumer(this, service);
         final Processor pipeline = Pipeline.newInstance(getCamelContext(), ceProcessor, processor);
-        final Consumer consumer = transport.createConsumer(this, service, pipeline);
+        final Consumer consumer = getComponent().getTransport().createConsumer(this, service, pipeline);
 
         PropertyBindingSupport.build()
             .withCamelContext(getCamelContext())