You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/03/04 18:25:15 UTC

[06/14] incubator-usergrid git commit: change queue listener bootstrap

change queue listener bootstrap


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/66f4bfb9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/66f4bfb9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/66f4bfb9

Branch: refs/heads/two-dot-o
Commit: 66f4bfb92f07f5eb066c175e94ffae4c39865998
Parents: 4d6bee0
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Mar 2 12:42:26 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Mar 2 12:42:26 2015 -0700

----------------------------------------------------------------------
 .../cassandra/EntityManagerFactoryImplIT.java   | 25 ++++++++++----------
 .../usergrid/rest/JobServiceBoostrap.java       | 12 ++++++++++
 .../services/notifications/QueueListener.java   |  9 +------
 .../resources/usergrid-services-context.xml     |  3 +--
 4 files changed, 26 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66f4bfb9/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index 3f42356..b4a67e8 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -40,6 +40,7 @@ import org.apache.usergrid.persistence.cassandra.util.TraceTagReporter;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.setup.ConcurrentProcessSingleton;
 import rx.functions.Func0;
+import rx.functions.Func1;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -123,12 +124,11 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         em.refreshIndex();
 
-        Func0<Boolean> func0 = new Func0<Boolean>() {
+        Func1< Map<String, UUID> ,Boolean> findDeletedApps = new Func1<Map<String, UUID> ,Boolean>() {
             @Override
-            public Boolean call() {
+            public Boolean call( Map<String, UUID> deletedApps) {
                 try {
                     boolean found = false;
-                    Map<String, UUID> deletedApps = emf.getDeletedApplications();
                     for (String appName : deletedApps.keySet()) {
                         UUID appId = deletedApps.get(appName);
                         if (appId.equals(applicationId)) {
@@ -145,11 +145,11 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         boolean found = false;
         for(int i=0;i<5;i++){
-            found = func0.call();
+            found = findDeletedApps.call(emf.getDeletedApplications());
             if(found){
                 break;
             } else{
-              Thread.sleep(100);
+              Thread.sleep(500);
             }
         }
         assertTrue("Deleted app not found in deleted apps collection", found );
@@ -180,22 +180,21 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         // it should not be found in the deleted apps collection
         for(int i=0;i<5;i++){
-            found = func0.call();
+            found = findDeletedApps.call(emf.getDeletedApplications());
             if(!found){
                 break;
             } else{
-                Thread.sleep(100);
+                Thread.sleep(500);
             }
         }
         assertFalse("Restored app found in deleted apps collection", found);
 
-        found = false;
-        appMap = setup.getEmf().getApplications();
-        for ( String appName : appMap.keySet() ) {
-            UUID appId = appMap.get( appName );
-            if ( appId.equals( applicationId )) {
-                found = true;
+        for(int i=0;i<5;i++){
+            found = findDeletedApps.call(setup.getEmf().getApplications());
+            if(!found){
                 break;
+            } else{
+                Thread.sleep(500);
             }
         }
         assertTrue("Restored app not found in apps collection", found);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66f4bfb9/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java b/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
index a921f22..ed45c91 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/JobServiceBoostrap.java
@@ -18,6 +18,7 @@ package org.apache.usergrid.rest;
 
 import org.apache.usergrid.batch.service.JobSchedulerService;
 import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.services.notifications.QueueListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +45,9 @@ public class JobServiceBoostrap implements
     @Autowired
     private Properties properties;
 
+    @Autowired
+    private QueueListener notificationsQueueListener;
+
     public JobServiceBoostrap() {
     }
 
@@ -65,6 +69,14 @@ public class JobServiceBoostrap implements
         } else {
             logger.info( "Scheduler Service disabled" );
         }
+
+        boolean shouldRun = new Boolean(properties.getProperty("usergrid.notifications.listener.run","true"));
+        if(shouldRun){
+            notificationsQueueListener.start();
+        }else{
+            logger.info("QueueListener: never started due to config value usergrid.notifications.listener.run.");
+        }
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66f4bfb9/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
index df27d2b..d34cc22 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
@@ -99,10 +99,7 @@ public class QueueListener  {
             int threadCount = 0;
 
             try {
-                boolean shouldRun = new Boolean(properties.getProperty("usergrid.notifications.listener.run","true"));
-                if(!shouldRun){
-                    return;
-                }
+
                 sleepBetweenRuns = new Long(properties.getProperty("usergrid.notifications.listener.sleep.between", ""+sleepBetweenRuns)).longValue();
                 sleepWhenNoneFound = new Long(properties.getProperty("usergrid.notifications.listener.sleep.after", ""+DEFAULT_SLEEP)).longValue();
                 batchSize = new Integer(properties.getProperty("usergrid.notifications.listener.batchSize", (""+batchSize)));
@@ -135,10 +132,6 @@ public class QueueListener  {
                 LOG.error("QueueListener: failed to start:", e);
             }
             LOG.info("QueueListener: done starting.");
-//        }else{
-//            LOG.info("QueueListener: never started due to config value usergrid.notifications.listener.run.");
-//        }
-
     }
 
     private void execute(){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/66f4bfb9/stack/services/src/main/resources/usergrid-services-context.xml
----------------------------------------------------------------------
diff --git a/stack/services/src/main/resources/usergrid-services-context.xml b/stack/services/src/main/resources/usergrid-services-context.xml
index e97481b..666051d 100644
--- a/stack/services/src/main/resources/usergrid-services-context.xml
+++ b/stack/services/src/main/resources/usergrid-services-context.xml
@@ -89,8 +89,7 @@
 
   <bean id="exportJob" class="org.apache.usergrid.management.export.ExportJob" />
 
-  <bean id="notificationsQueueListener" class="org.apache.usergrid.services.notifications.QueueListener"
-        scope="singleton">
+  <bean id="notificationsQueueListener" class="org.apache.usergrid.services.notifications.QueueListener">
     <constructor-arg name="emf" ref="entityManagerFactory" />
     <constructor-arg name="props" ref="properties" />
     <constructor-arg name="smf" ref="serviceManagerFactory" />