You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2020/08/16 20:29:59 UTC

[karaf-cellar] branch master updated: [KARAF-6814] Add wait on Cellar configuraion (group and node)

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf-cellar.git


The following commit(s) were added to refs/heads/master by this push:
     new 0591bbe  [KARAF-6814] Add wait on Cellar configuraion (group and node)
0591bbe is described below

commit 0591bbe4f7feabc10402424c21648d6613b968be
Author: jbonofre <jb...@apache.org>
AuthorDate: Sun Aug 16 22:29:18 2020 +0200

    [KARAF-6814] Add wait on Cellar configuraion (group and node)
---
 .../cellar/hazelcast/HazelcastGroupManager.java    | 28 ++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
index f328239..6108b2e 100644
--- a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
+++ b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
@@ -73,7 +73,7 @@ public class HazelcastGroupManager implements GroupManager, EntryListener<String
 
             if (hazelcastGroupsConfig.isEmpty()) {
                 // First one to be here - initialize hazelcast map with local configuration
-                LOGGER.debug("CELLAR HAZELCAST: intialize cluster with local config");
+                LOGGER.debug("CELLAR HAZELCAST: initialize cluster with local config");
 
                 Map<String, Object> updates = getUpdatesForHazelcastMap(properties);
                 hazelcastGroupsConfig.putAll(updates);
@@ -343,7 +343,7 @@ public class HazelcastGroupManager implements GroupManager, EntryListener<String
     public Map<String, Group> listGroups() {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
-            Map<String, Group> res = new HashMap<String, Group>();
+            Map<String, Group> res = new HashMap<>();
             Thread.currentThread().setContextClassLoader(combinedClassLoader);
             Map<Node, Set<String>> nodes = getClusterGroups();
 
@@ -806,10 +806,34 @@ public class HazelcastGroupManager implements GroupManager, EntryListener<String
     }
 
     private Configuration getConfigurationForGroups() throws IOException {
+        try {
+            int max = 0;
+            while (configurationAdmin.listConfigurations("(service.pid=" + Configurations.GROUP + ")") == null && max < 100) {
+                Thread.sleep(500);
+                max++;
+            }
+            if (max == 100) {
+                LOGGER.warn("Timeout while loading {} configuration", Configurations.GROUP);
+            }
+        } catch (Exception e) {
+            throw new IOException(e);
+        }
         return configurationAdmin.getConfiguration(Configurations.GROUP, null);
     }
 
     private Configuration getConfigurationForNode() throws IOException {
+        try {
+            int max = 0;
+            while (configurationAdmin.listConfigurations("(service.pid=" + Configurations.NODE + ")") == null && max < 100) {
+                Thread.sleep(500);
+                max++;
+            }
+            if (max == 100) {
+                LOGGER.warn("Timeout while loading {} configuration", Configurations.NODE);
+            }
+        } catch (Exception e) {
+            throw new IOException(e);
+        }
         return configurationAdmin.getConfiguration(Configurations.NODE, null);
     }