camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] git commit: CAMEL-6722: binding component - Should start/stop its child services
Date Tue, 10 Sep 2013 09:11:30 GMT
CAMEL-6722: binding component - Should start/stop its child services


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/19df5be9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/19df5be9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/19df5be9

Branch: refs/heads/camel-2.12.x
Commit: 19df5be9fd49a62b9a90a2b0b03afb5ec459d4a2
Parents: 4d7e7e1
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Sep 10 10:25:39 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Sep 10 11:11:18 2013 +0200

----------------------------------------------------------------------
 .../camel/component/binding/BindingComponent.java |  3 ++-
 .../binding/BindingConsumerProcessor.java         | 12 ++++++++++--
 .../camel/component/binding/BindingEndpoint.java  | 18 +++++++++++++++++-
 .../component/binding/BindingNameComponent.java   |  1 -
 .../camel/component/binding/BindingProducer.java  | 12 ++++++++++--
 .../processor/binding/DataFormatBinding.java      | 14 ++++++++++++--
 6 files changed, 51 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/19df5be9/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java
b/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java
index 933ed00..f3497ba 100644
--- a/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/binding/BindingComponent.java
@@ -81,10 +81,11 @@ public class BindingComponent extends DefaultComponent {
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         Binding bindingValue = getBinding();
         ObjectHelper.notNull(bindingValue, "binding");
+
         CamelContext camelContext = getCamelContext();
         String delegateURI = createDelegateURI(remaining, parameters);
         Endpoint delegate = getMandatoryEndpoint(camelContext, delegateURI);
-        return new BindingEndpoint(uri, this, bindingValue,  delegate);
+        return new BindingEndpoint(uri, this, bindingValue, delegate);
     }
 
     protected String createDelegateURI(String remaining, Map<String, Object> parameters)
{

http://git-wip-us.apache.org/repos/asf/camel/blob/19df5be9/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java
b/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java
index 9a3d897..f6d8b80 100644
--- a/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/component/binding/BindingConsumerProcessor.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.binding;
 
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.support.ServiceSupport;
@@ -42,11 +43,18 @@ public class BindingConsumerProcessor extends ServiceSupport implements
Processo
 
     @Override
     protected void doStart() throws Exception {
-        ServiceHelper.startService(bindingProcessor);
+        // inject CamelContext
+        if (bindingProcessor instanceof CamelContextAware) {
+            ((CamelContextAware) bindingProcessor).setCamelContext(endpoint.getCamelContext());
+        }
+        if (delegateProcessor instanceof CamelContextAware) {
+            ((CamelContextAware) delegateProcessor).setCamelContext(endpoint.getCamelContext());
+        }
+        ServiceHelper.startServices(bindingProcessor, delegateProcessor);
     }
 
     @Override
     protected void doStop() throws Exception {
-        ServiceHelper.stopService(bindingProcessor);
+        ServiceHelper.stopServices(delegateProcessor, bindingProcessor);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/19df5be9/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java
b/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java
index c45c76e..1c44fb3 100644
--- a/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.binding;
 
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
@@ -26,6 +27,7 @@ import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.Binding;
 import org.apache.camel.spi.HasBinding;
 import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.ServiceHelper;
 
 /**
  * Applies a {@link org.apache.camel.spi.Binding} to an underlying {@link Endpoint} so that
the binding processes messages
@@ -67,7 +69,6 @@ public class BindingEndpoint extends DefaultEndpoint implements HasBinding
{
         return delegate;
     }
 
-
     /**
      * Applies the {@link Binding} processor to the given exchange before passing it on to
the delegateProcessor (either a producer or consumer)
      */
@@ -93,4 +94,19 @@ public class BindingEndpoint extends DefaultEndpoint implements HasBinding
{
         return answer;
     }
 
+    @Override
+    protected void doStart() throws Exception {
+        // inject CamelContext
+        if (binding instanceof CamelContextAware) {
+            ((CamelContextAware) binding).setCamelContext(getCamelContext());
+        }
+        ServiceHelper.startServices(delegate, binding);
+        super.doStart();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        ServiceHelper.stopServices(delegate, binding);
+        super.doStop();
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/19df5be9/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java
b/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java
index 53294d3..211b56b 100644
--- a/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/binding/BindingNameComponent.java
@@ -36,7 +36,6 @@ public class BindingNameComponent extends DefaultComponent {
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-
         CamelContext camelContext = getCamelContext();
         int idx = remaining.indexOf(":");
         if (idx <= 0) {

http://git-wip-us.apache.org/repos/asf/camel/blob/19df5be9/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java
b/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java
index 2bb40eb..4d728e7 100644
--- a/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/binding/BindingProducer.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.binding;
 
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -34,8 +35,8 @@ public class BindingProducer extends DefaultProducer {
     public BindingProducer(BindingEndpoint endpoint) throws Exception {
         super(endpoint);
         this.endpoint = endpoint;
-        bindingProcessor = endpoint.getBinding().createProduceProcessor();
-        delegateProducer = endpoint.getDelegate().createProducer();
+        this.bindingProcessor = endpoint.getBinding().createProduceProcessor();
+        this.delegateProducer = endpoint.getDelegate().createProducer();
     }
 
     @Override
@@ -45,6 +46,13 @@ public class BindingProducer extends DefaultProducer {
 
     @Override
     protected void doStart() throws Exception {
+        // inject CamelContext
+        if (bindingProcessor instanceof CamelContextAware) {
+            ((CamelContextAware) bindingProcessor).setCamelContext(getEndpoint().getCamelContext());
+        }
+        if (delegateProducer instanceof CamelContextAware) {
+            ((CamelContextAware) delegateProducer).setCamelContext(getEndpoint().getCamelContext());
+        }
         ServiceHelper.startServices(bindingProcessor, delegateProducer);
         super.doStart();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/19df5be9/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java
b/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java
index dab786e..bd4c597 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/binding/DataFormatBinding.java
@@ -21,13 +21,14 @@ import org.apache.camel.processor.MarshalProcessor;
 import org.apache.camel.processor.UnmarshalProcessor;
 import org.apache.camel.spi.Binding;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
 
 /**
  * Represents a {@link org.apache.camel.spi.Binding} which Marshals the message in the ProduceProcessor
and
  * Unmarshals the message in the ConsumeProcessor
  */
-public class DataFormatBinding implements Binding {
+public class DataFormatBinding extends ServiceSupport implements Binding {
     private DataFormat producerDataFormat;
     private DataFormat consumerDataFormat;
 
@@ -63,7 +64,6 @@ public class DataFormatBinding implements Binding {
         setProducerDataFormat(dataFormat);
     }
 
-
     public DataFormat getConsumerDataFormat() {
         return consumerDataFormat;
     }
@@ -79,4 +79,14 @@ public class DataFormatBinding implements Binding {
     public void setProducerDataFormat(DataFormat producerDataFormat) {
         this.producerDataFormat = producerDataFormat;
     }
+
+    @Override
+    protected void doStart() throws Exception {
+        // noop
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        // noop
+    }
 }


Mime
View raw message