camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [2/5] camel git commit: CAMEL-11020: Camel Kubernetes consumers do not close watchers - Pods Consumer
Date Thu, 16 Mar 2017 12:21:01 GMT
CAMEL-11020: Camel Kubernetes consumers do not close watchers - Pods Consumer


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

Branch: refs/heads/master
Commit: f617baaa1629e9a167e779324c8ed6630cbad791
Parents: 5846f22
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Mar 16 11:46:49 2017 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Mar 16 13:20:46 2017 +0100

----------------------------------------------------------------------
 .../consumer/KubernetesPodsConsumer.java        | 25 +++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f617baaa/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java
index 6aa688e..76222c0 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesPodsConsumer.java
@@ -22,6 +22,7 @@ import io.fabric8.kubernetes.api.model.DoneablePod;
 import io.fabric8.kubernetes.api.model.Pod;
 import io.fabric8.kubernetes.api.model.PodList;
 import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watch;
 import io.fabric8.kubernetes.client.Watcher;
 import io.fabric8.kubernetes.client.dsl.MixedOperation;
 import io.fabric8.kubernetes.client.dsl.PodResource;
@@ -42,6 +43,7 @@ public class KubernetesPodsConsumer extends DefaultConsumer {
 
     private final Processor processor;
     private ExecutorService executor;
+    private PodsConsumerTask podsWatcher;
 
     public KubernetesPodsConsumer(KubernetesEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
@@ -57,8 +59,9 @@ public class KubernetesPodsConsumer extends DefaultConsumer {
     protected void doStart() throws Exception {
         super.doStart();
         executor = getEndpoint().createExecutor();
-
-        executor.submit(new PodsConsumerTask());
+        
+        podsWatcher = new PodsConsumerTask();
+        executor.submit(podsWatcher);
     }
 
     @Override
@@ -68,8 +71,14 @@ public class KubernetesPodsConsumer extends DefaultConsumer {
         LOG.debug("Stopping Kubernetes Pods Consumer");
         if (executor != null) {
             if (getEndpoint() != null && getEndpoint().getCamelContext() != null)
{
+                if (podsWatcher != null) {
+                    podsWatcher.getWatch().close();
+                }
                 getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor);
             } else {
+                if (podsWatcher != null) {
+                    podsWatcher.getWatch().close();
+                }
                 executor.shutdownNow();
             }
         }
@@ -77,6 +86,8 @@ public class KubernetesPodsConsumer extends DefaultConsumer {
     }
 
     class PodsConsumerTask implements Runnable {
+
+        private Watch watch;
         
         @Override
         public void run() {
@@ -91,7 +102,7 @@ public class KubernetesPodsConsumer extends DefaultConsumer {
             if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getResourceName()))
{
                 w.withName(getEndpoint().getKubernetesConfiguration().getResourceName());
             }
-            w.watch(new Watcher<Pod>() {
+            watch = w.watch(new Watcher<Pod>() {
 
                 @Override
                 public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action,
@@ -116,6 +127,14 @@ public class KubernetesPodsConsumer extends DefaultConsumer {
 
                 }
             });
+        }
+
+        public Watch getWatch() {
+            return watch;
+        }
+
+        public void setWatch(Watch watch) {
+            this.watch = watch;
         } 
     }
 }


Mime
View raw message