This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 4110f1c CAMEL-17121: converted camel-zookeeper to repeatable tasks 4110f1c is described below commit 4110f1c480fc6a2fbf6ba48537312805ea529532 Author: Otavio Rodolfo Piske <opi...@redhat.com> AuthorDate: Tue Nov 9 13:07:23 2021 +0100 CAMEL-17121: converted camel-zookeeper to repeatable tasks --- .../zookeeper/cluster/ZooKeeperClusterView.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusterView.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusterView.java index 352b67e..74ec1fe 100644 --- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusterView.java +++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusterView.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.zookeeper.cluster; +import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -26,6 +27,10 @@ import org.apache.camel.cluster.CamelClusterMember; import org.apache.camel.cluster.CamelClusterService; import org.apache.camel.component.zookeeper.ZooKeeperCuratorConfiguration; import org.apache.camel.support.cluster.AbstractCamelClusterView; +import org.apache.camel.support.task.BlockingTask; +import org.apache.camel.support.task.Tasks; +import org.apache.camel.support.task.budget.Budgets; +import org.apache.camel.support.task.budget.IterationBoundedBudget; import org.apache.camel.util.ObjectHelper; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.leader.LeaderSelector; @@ -133,14 +138,13 @@ final class ZooKeeperClusterView extends AbstractCamelClusterView { public void takeLeadership(CuratorFramework curatorFramework) throws Exception { fireLeadershipChangedEvent(Optional.of(localMember)); - while (isRunAllowed()) { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - Thread.interrupted(); - break; - } - } + BlockingTask task = Tasks.foregroundTask().withBudget(Budgets.iterationBudget() + .withMaxIterations(IterationBoundedBudget.UNLIMITED_ITERATIONS) + .withInterval(Duration.ofSeconds(5)) + .build()) + .build(); + + task.run(() -> !isRunAllowed()); fireLeadershipChangedEvent(getLeader()); }