stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject stratos git commit: Moving hazelcast instance initialization waiting logic to a thread
Date Wed, 03 Dec 2014 21:48:52 GMT
Repository: stratos
Updated Branches:
  refs/heads/master d5c4a6739 -> 5e6aca3a0


Moving hazelcast instance initialization waiting logic to a thread


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

Branch: refs/heads/master
Commit: 5e6aca3a0fd510efd9f7be4e94e4e8e95c4ff056
Parents: d5c4a67
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Thu Dec 4 03:18:43 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Thu Dec 4 03:18:43 2014 +0530

----------------------------------------------------------------------
 .../internal/StratosCommonServiceComponent.java | 44 +++++++++++++-------
 1 file changed, 30 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/5e6aca3a/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 13d9b2a..e4f0514 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
@@ -58,7 +58,7 @@ public class StratosCommonServiceComponent {
 
     protected void activate(ComponentContext context) {
         try {
-            BundleContext bundleContext = context.getBundleContext();
+            final BundleContext bundleContext = context.getBundleContext();
             if (CommonUtil.getStratosConfig() == null) {
                 StratosConfiguration stratosConfig = CommonUtil.loadStratosConfiguration();
                 CommonUtil.setStratosConfig(stratosConfig);
@@ -72,22 +72,33 @@ public class StratosCommonServiceComponent {
 
             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");
+                Thread thread = new Thread() {
+                    @Override
+                    public void run() {
+                        try {
+                            // 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");
+                                }
+                            }
+                            registerDistributedObjectProviderService(bundleContext);
+                        } catch (Exception e) {
+                            log.error(e);
+                        }
                     }
-                }
+                };
+                thread.setName("Distributed object provider registration thread");
+                thread.start();
+            } else {
+                // Register distributed object provider service
+                registerDistributedObjectProviderService(bundleContext);
             }
 
-            // Register distributed object provider service
-            DistributedObjectProvider distributedObjectProvider = new HazelcastDistributedObjectProvider();
-            bundleContext.registerService(DistributedObjectProvider.class, distributedObjectProvider,
null);
-
             // Register manager configuration OSGI service
             try {
                 StratosConfiguration stratosConfiguration = CommonUtil.loadStratosConfiguration();
@@ -105,6 +116,11 @@ public class StratosCommonServiceComponent {
         }
     }
 
+    private void registerDistributedObjectProviderService(BundleContext bundleContext) {
+        DistributedObjectProvider distributedObjectProvider = new HazelcastDistributedObjectProvider();
+        bundleContext.registerService(DistributedObjectProvider.class, distributedObjectProvider,
null);
+    }
+
     protected void deactivate(ComponentContext context) {
         log.debug("Stratos common service is deactivated");
     }


Mime
View raw message