stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject stratos git commit: Adding logic to wait until hazelcast instance to be initialized
Date Wed, 03 Dec 2014 21:38:36 GMT
Repository: stratos
Updated Branches:
  refs/heads/master fd5c273d0 -> d5c4a6739


Adding logic to wait until hazelcast instance to be initialized


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

Branch: refs/heads/master
Commit: d5c4a67391a7fbddfe9fccf0deb0203837d311cb
Parents: fd5c273
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Thu Dec 4 03:08:26 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Thu Dec 4 03:08:26 2014 +0530

----------------------------------------------------------------------
 .../common/constants/StratosConstants.java        |  2 ++
 .../internal/StratosCommonServiceComponent.java   | 18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/d5c4a673/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
index 36a0f20..fd44b9f 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
@@ -185,5 +185,7 @@ public class StratosConstants {
 	public static final String NO_LOAD_BALANCER = "no.load.balancer";
 	public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
 	public static final String LOAD_BALANCED_SERVICE_TYPE = "load.balanced.service.type";
+
+    public static final long HAZELCAST_INSTANCE_INIT_TIMEOUT = 300000; // 5 min
 }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/d5c4a673/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java
b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java
index 2ea1cd7..13d9b2a 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java
@@ -19,10 +19,12 @@
 package org.apache.stratos.common.internal;
 
 import com.hazelcast.core.HazelcastInstance;
+import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.clustering.DistributedObjectProvider;
 import org.apache.stratos.common.clustering.impl.HazelcastDistributedObjectProvider;
+import org.apache.stratos.common.constants.StratosConstants;
 import org.apache.stratos.common.util.CommonUtil;
 import org.apache.stratos.common.util.StratosConfiguration;
 import org.osgi.framework.BundleContext;
@@ -68,6 +70,20 @@ public class StratosCommonServiceComponent {
                 CommonUtil.setEula(eula);
             }
 
+            AxisConfiguration axisConfig = ServiceReferenceHolder.getInstance().getAxisConfiguration();
+            if((axisConfig != null) && (axisConfig.getClusteringAgent() != null))
{
+                // Wait for the hazelcast instance to be available
+                long startTime = System.currentTimeMillis();
+                log.info("Waiting for the hazelcast instance to be initialized...");
+                while(ServiceReferenceHolder.getInstance().getHazelcastInstance() == null)
{
+                    Thread.sleep(1000);
+                    if((System.currentTimeMillis() - startTime) >= StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT)
{
+                        throw new RuntimeException("Hazelcast instance was not initialized
within "
+                                + StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT /1000
+ " seconds");
+                    }
+                }
+            }
+
             // Register distributed object provider service
             DistributedObjectProvider distributedObjectProvider = new HazelcastDistributedObjectProvider();
             bundleContext.registerService(DistributedObjectProvider.class, distributedObjectProvider,
null);
@@ -85,7 +101,7 @@ public class StratosCommonServiceComponent {
                 log.info("Stratos common service bundle is activated");
             }
         } catch (Throwable e) {
-            log.error("Error in activating stratos common service component" + e.toString());
+            log.error("Error in activating stratos common service component", e);
         }
     }
 


Mime
View raw message