camel-commits mailing list archives

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


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

Branch: refs/heads/master
Commit: d44034ad5a6c2874521408eb61223ccc818b381b
Parents: 99fca0a
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Mar 16 11:56:42 2017 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Mar 16 13:20:47 2017 +0100

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


http://git-wip-us.apache.org/repos/asf/camel/blob/d44034ad/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNodesConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNodesConsumer.java
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNodesConsumer.java
index 14008a8..557c07b 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNodesConsumer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesNodesConsumer.java
@@ -22,6 +22,7 @@ import io.fabric8.kubernetes.api.model.DoneableNode;
 import io.fabric8.kubernetes.api.model.Node;
 import io.fabric8.kubernetes.api.model.NodeList;
 import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watch;
 import io.fabric8.kubernetes.client.Watcher;
 import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
 import io.fabric8.kubernetes.client.dsl.Resource;
@@ -42,6 +43,7 @@ public class KubernetesNodesConsumer extends DefaultConsumer {
 
     private final Processor processor;
     private ExecutorService executor;
+    private NodesConsumerTask nodesWatcher;
 
     public KubernetesNodesConsumer(KubernetesEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
@@ -58,7 +60,8 @@ public class KubernetesNodesConsumer extends DefaultConsumer {
         super.doStart();
         executor = getEndpoint().createExecutor();
 
-        executor.submit(new NodesConsumerTask());
+        nodesWatcher = new NodesConsumerTask();
+        executor.submit(nodesWatcher);
     }
 
     @Override
@@ -68,8 +71,14 @@ public class KubernetesNodesConsumer extends DefaultConsumer {
         LOG.debug("Stopping Kubernetes Nodes Consumer");
         if (executor != null) {
             if (getEndpoint() != null && getEndpoint().getCamelContext() != null)
{
+                if (nodesWatcher != null) {
+                	nodesWatcher.getWatch().close();
+                }
                 getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor);
             } else {
+                if (nodesWatcher != null) {
+                	nodesWatcher.getWatch().close();
+                }
                 executor.shutdownNow();
             }
         }
@@ -78,6 +87,8 @@ public class KubernetesNodesConsumer extends DefaultConsumer {
 
     class NodesConsumerTask implements Runnable {
         
+        private Watch watch;
+        
         @Override
         public void run() {
             NonNamespaceOperation<Node, NodeList, DoneableNode, Resource<Node, DoneableNode>>
w = getEndpoint().getKubernetesClient().nodes();
@@ -88,7 +99,7 @@ public class KubernetesNodesConsumer extends DefaultConsumer {
             if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getResourceName()))
{
                 w.withName(getEndpoint().getKubernetesConfiguration().getResourceName());
             }
-            w.watch(new Watcher<Node>() {
+            watch = w.watch(new Watcher<Node>() {
 
                 @Override
                 public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action,
@@ -113,6 +124,14 @@ public class KubernetesNodesConsumer extends DefaultConsumer {
 
                 }
             });
+        }
+       
+        public Watch getWatch() {
+            return watch;
+        }
+
+        public void setWatch(Watch watch) {
+            this.watch = watch;
         } 
     }
 }


Mime
View raw message