camel-commits mailing list archives

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


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

Branch: refs/heads/camel-2.18.x
Commit: e0a2a9eb97dc4355c59afd5ecd3f2424e0a34ec1
Parents: 1f92f81
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Mar 16 12:14:43 2017 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Mar 16 13:11:35 2017 +0100

----------------------------------------------------------------------
 ...ubernetesReplicationControllersConsumer.java | 26 +++++++++++++++++---
 1 file changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e0a2a9eb/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java
index 76c8347..0081bc6 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesReplicationControllersConsumer.java
@@ -25,6 +25,7 @@ import io.fabric8.kubernetes.api.model.PodList;
 import io.fabric8.kubernetes.api.model.ReplicationController;
 import io.fabric8.kubernetes.api.model.ReplicationControllerList;
 import io.fabric8.kubernetes.client.KubernetesClientException;
+import io.fabric8.kubernetes.client.Watch;
 import io.fabric8.kubernetes.client.Watcher;
 import io.fabric8.kubernetes.client.dsl.ClientMixedOperation;
 import io.fabric8.kubernetes.client.dsl.ClientPodResource;
@@ -46,6 +47,7 @@ public class KubernetesReplicationControllersConsumer extends DefaultConsumer
{
 
     private final Processor processor;
     private ExecutorService executor;
+    private ReplicationControllersConsumerTask rcWatcher;
 
     public KubernetesReplicationControllersConsumer(KubernetesEndpoint endpoint, Processor
processor) {
         super(endpoint, processor);
@@ -62,8 +64,8 @@ public class KubernetesReplicationControllersConsumer extends DefaultConsumer
{
         super.doStart();
 
         executor = getEndpoint().createExecutor();
-
-        executor.submit(new ReplicationControllersConsumerTask());       
+        rcWatcher = new ReplicationControllersConsumerTask();
+        executor.submit(rcWatcher);       
     }
 
     @Override
@@ -73,8 +75,14 @@ public class KubernetesReplicationControllersConsumer extends DefaultConsumer
{
         LOG.debug("Stopping Kubernetes Replication Controllers Consumer");
         if (executor != null) {
             if (getEndpoint() != null && getEndpoint().getCamelContext() != null)
{
+                if (rcWatcher != null) {
+                    rcWatcher.getWatch().close();
+                }
                 getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor);
             } else {
+                if (rcWatcher != null) {
+                    rcWatcher.getWatch().close();
+                }
                 executor.shutdownNow();
             }
         }
@@ -82,7 +90,9 @@ public class KubernetesReplicationControllersConsumer extends DefaultConsumer
{
     }
     
     class ReplicationControllersConsumerTask implements Runnable {
-         
+        
+        private Watch watch;
+        
         @Override
         public void run() {
             ClientMixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController,

@@ -97,7 +107,7 @@ public class KubernetesReplicationControllersConsumer extends DefaultConsumer
{
             if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getResourceName()))
{
                 w.withName(getEndpoint().getKubernetesConfiguration().getResourceName());
             }
-            w.watch(new Watcher<ReplicationController>() {
+            watch = w.watch(new Watcher<ReplicationController>() {
 
                 @Override
                 public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action,
@@ -124,5 +134,13 @@ public class KubernetesReplicationControllersConsumer extends DefaultConsumer
{
 
             });
         }
+        
+        public Watch getWatch() {
+            return watch;
+        }
+
+        public void setWatch(Watch watch) {
+            this.watch = watch;
+        } 
     }
 }


Mime
View raw message