camel-commits mailing list archives

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


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

Branch: refs/heads/camel-2.18.x
Commit: 1f92f814f85f2daa9b2f811b741e280a2d16c5c9
Parents: c2add9f
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Mar 16 11:50:56 2017 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Mar 16 13:09:07 2017 +0100

----------------------------------------------------------------------
 .../consumer/KubernetesNamespacesConsumer.java  | 23 ++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1f92f814/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNamespacesConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNamespacesConsumer.java
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNamespacesConsumer.java
index 9e09105..51d5abe 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNamespacesConsumer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNamespacesConsumer.java
@@ -22,6 +22,7 @@ import io.fabric8.kubernetes.api.model.DoneableNamespace;
 import io.fabric8.kubernetes.api.model.Namespace;
 import io.fabric8.kubernetes.api.model.NamespaceList;
 import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watch;
 import io.fabric8.kubernetes.client.Watcher;
 import io.fabric8.kubernetes.client.dsl.ClientNonNamespaceOperation;
 import io.fabric8.kubernetes.client.dsl.ClientResource;
@@ -42,6 +43,7 @@ public class KubernetesNamespacesConsumer extends DefaultConsumer {
     
     private final Processor processor;
     private ExecutorService executor;
+    private NamespacesConsumerTask nsWatcher;
 
     public KubernetesNamespacesConsumer(KubernetesEndpoint endpoint, Processor processor)
{
         super(endpoint, processor);
@@ -58,7 +60,8 @@ public class KubernetesNamespacesConsumer extends DefaultConsumer {
         super.doStart();
         executor = getEndpoint().createExecutor();
         
-        executor.submit(new NamespacesConsumerTask());
+        nsWatcher = new NamespacesConsumerTask();
+        executor.submit(nsWatcher);
     }
 
     @Override
@@ -68,8 +71,14 @@ public class KubernetesNamespacesConsumer extends DefaultConsumer {
         LOG.debug("Stopping Kubernetes Namespace Consumer");
         if (executor != null) {
             if (getEndpoint() != null && getEndpoint().getCamelContext() != null)
{
+                if (nsWatcher != null) {
+                    nsWatcher.getWatch().close();
+                }
                 getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor);
             } else {
+                if (nsWatcher != null) {
+                    nsWatcher.getWatch().close();
+                }
                 executor.shutdownNow();
             }
         }
@@ -77,6 +86,8 @@ public class KubernetesNamespacesConsumer extends DefaultConsumer {
     }
     
     class NamespacesConsumerTask implements Runnable {
+
+        private Watch watch;
         
         @Override
         public void run() {
@@ -84,7 +95,7 @@ public class KubernetesNamespacesConsumer extends DefaultConsumer {
             if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getNamespace()))
{
                 w.withName(getEndpoint().getKubernetesConfiguration().getNamespace());
             }
-            w.watch(new Watcher<Namespace>() {
+            watch = w.watch(new Watcher<Namespace>() {
 
                 @Override
                 public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action,
@@ -108,6 +119,14 @@ public class KubernetesNamespacesConsumer extends DefaultConsumer {
                     }                            
                 }
             });
+        }
+        
+        public Watch getWatch() {
+            return watch;
+        }
+
+        public void setWatch(Watch watch) {
+            this.watch = watch;
         } 
     }
 }


Mime
View raw message