camel-commits mailing list archives

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


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

Branch: refs/heads/camel-2.18.x
Commit: 49adc55b7c5cbc99f32f67095e5c7e99fe5cff23
Parents: e0a2a9e
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Mar 16 13:06:58 2017 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Mar 16 13:12:00 2017 +0100

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


http://git-wip-us.apache.org/repos/asf/camel/blob/49adc55b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java
b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java
index 2d658bb..e117bc0 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/consumer/KubernetesServicesConsumer.java
@@ -22,6 +22,7 @@ import io.fabric8.kubernetes.api.model.DoneableService;
 import io.fabric8.kubernetes.api.model.Service;
 import io.fabric8.kubernetes.api.model.ServiceList;
 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.ClientResource;
@@ -42,6 +43,7 @@ public class KubernetesServicesConsumer extends DefaultConsumer {
 
     private final Processor processor;
     private ExecutorService executor;
+    private ServicesConsumerTask servicesWatcher;
 
     public KubernetesServicesConsumer(KubernetesEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
@@ -58,7 +60,8 @@ public class KubernetesServicesConsumer extends DefaultConsumer {
         super.doStart();
         executor = getEndpoint().createExecutor();
 
-        executor.submit(new ServicesConsumerTask());       
+        servicesWatcher = new ServicesConsumerTask();
+        executor.submit(servicesWatcher);       
 
     }
 
@@ -68,8 +71,14 @@ public class KubernetesServicesConsumer extends DefaultConsumer {
         LOG.debug("Stopping Kubernetes Services Consumer");
         if (executor != null) {
             if (getEndpoint() != null && getEndpoint().getCamelContext() != null)
{
+                if (servicesWatcher != null) {
+                    servicesWatcher.getWatch().close();
+                }
                 getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor);
             } else {
+                if (servicesWatcher != null) {
+                    servicesWatcher.getWatch().close();
+                }
                 executor.shutdownNow();
             }
         }
@@ -78,6 +87,8 @@ public class KubernetesServicesConsumer extends DefaultConsumer {
     
     class ServicesConsumerTask implements Runnable {
         
+        private Watch watch;
+        
         @Override
         public void run() {
             ClientMixedOperation<Service, ServiceList, DoneableService, ClientResource<Service,
DoneableService>> w = getEndpoint().getKubernetesClient().services();
@@ -91,7 +102,7 @@ public class KubernetesServicesConsumer extends DefaultConsumer {
             if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getResourceName()))
{
                 w.withName(getEndpoint().getKubernetesConfiguration().getResourceName());
             }
-            w.watch(new Watcher<Service>() {
+            watch = w.watch(new Watcher<Service>() {
 
                 @Override
                 public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action,
@@ -118,5 +129,13 @@ public class KubernetesServicesConsumer extends DefaultConsumer {
 
             });
         } 
+        
+        public Watch getWatch() {
+            return watch;
+        }
+
+        public void setWatch(Watch watch) {
+            this.watch = watch;
+        } 
     }
 }


Mime
View raw message