usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject [1/2] usergrid git commit: Changed notification object to accept both Integers and Long in the map.
Date Thu, 05 May 2016 16:59:40 GMT
Repository: usergrid
Updated Branches:
  refs/heads/9f45130_app_cache_fix 26959622a -> 4c1ece97c


Changed notification object to accept both Integers and Long in the map.


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

Branch: refs/heads/9f45130_app_cache_fix
Commit: a737708f12ff9d48ae69c122cecba943334b29c6
Parents: 2695962
Author: George Reyes <grey@apache.org>
Authored: Wed May 4 16:54:33 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Wed May 4 16:54:33 2016 -0700

----------------------------------------------------------------------
 .../persistence/entities/Notification.java      | 37 +++++++----
 .../impl/ApplicationQueueManagerImpl.java       | 66 +++++++++++++++-----
 .../AbstractServiceNotificationIT.java          | 26 +++-----
 3 files changed, 86 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/a737708f/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
index 5c3ee89..26b6595 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -17,16 +17,26 @@
 package org.apache.usergrid.persistence.entities;
 
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
 import javax.xml.bind.annotation.XmlRootElement;
-import java.util.*;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.TypedEntity;
 import org.apache.usergrid.persistence.annotations.EntityCollection;
 import org.apache.usergrid.persistence.annotations.EntityProperty;
 import org.apache.usergrid.persistence.index.query.Identifier;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
 /**
  * The entity class for representing Notifications.
  */
@@ -99,7 +109,7 @@ public class Notification extends TypedEntity {
 
     /** Map containing a count for "sent" and "errors" */
     @EntityProperty
-    protected Map<String, Long> statistics;
+    protected Map<String, Object> statistics;
 
 
     public Notification() {
@@ -228,23 +238,28 @@ public class Notification extends TypedEntity {
     }
 
     @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-    public Map<String, Long> getStatistics() {
+    public Map<String, Object> getStatistics() {
         return statistics;
     }
 
-    public void setStatistics(Map<String, Long> statistics) {
+    public void setStatistics(Map<String, Object> statistics) {
         this.statistics = statistics;
     }
 
     public void updateStatistics(long sent, long errors) {
         if (this.statistics == null) {
-            this.statistics = new HashMap<String, Long>(2);
+            this.statistics = new HashMap<String, Object>(2);
             this.statistics.put("sent", sent);
             this.statistics.put("errors", errors);
         } else {
-            this.statistics.put("sent", sent + this.statistics.get("sent"));
-            this.statistics.put("errors",
-                    errors + this.statistics.get("errors"));
+            if(this.statistics.get( "sent" ) instanceof Integer){
+                this.statistics.put( "sent", sent + (Integer) this.statistics.get( "sent"
) );
+                this.statistics.put( "errors", errors + (Integer) this.statistics.get( "errors"
) );
+            }
+            else if (this.statistics.get( "sent" ) instanceof Long ) {
+                this.statistics.put( "sent", sent + (Long) this.statistics.get( "sent" )
);
+                this.statistics.put( "errors", errors + (Long) this.statistics.get( "errors"
) );
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a737708f/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
index 12a47b6..6a8a4c8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
@@ -16,28 +16,52 @@
  */
 package org.apache.usergrid.services.notifications.impl;
 
-import com.codahale.metrics.Meter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.usergrid.batch.JobExecution;
-import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.ResultsIterator;
+import org.apache.usergrid.persistence.SimpleEntityRef;
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
 import org.apache.usergrid.persistence.entities.Device;
 import org.apache.usergrid.persistence.entities.Notification;
 import org.apache.usergrid.persistence.entities.Notifier;
 import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.persistence.Query;
 import org.apache.usergrid.persistence.queue.QueueManager;
 import org.apache.usergrid.persistence.queue.QueueMessage;
-import org.apache.usergrid.services.notifications.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.usergrid.services.notifications.ApplicationQueueManager;
+import org.apache.usergrid.services.notifications.ApplicationQueueMessage;
+import org.apache.usergrid.services.notifications.JobScheduler;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.ProviderAdapterFactory;
+import org.apache.usergrid.services.notifications.TaskManager;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import com.codahale.metrics.Meter;
+
 import rx.Observable;
 import rx.Subscriber;
 import rx.functions.Func1;
 
-import java.util.*;
-import java.util.concurrent.*;
-import java.util.concurrent.atomic.AtomicInteger;
-
 
 public class ApplicationQueueManagerImpl implements ApplicationQueueManager {
 
@@ -460,13 +484,23 @@ public class ApplicationQueueManagerImpl implements ApplicationQueueManager
{
 
 
     private boolean isOkToSend(Notification notification) {
-        Map<String, Long> stats = notification.getStatistics();
-        if (stats != null && notification.getExpectedCount() == (stats.get("sent")
+ stats.get("errors"))) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("notification {} already processed. not sending.",
-                    notification.getUuid());
+        Map<String, Object> stats = notification.getStatistics();
+        if(stats!=null && stats.get( "sent" )instanceof Integer) {
+            if ( notification.getExpectedCount() == ( (Integer ) stats.get( "sent" ) + (Integer
) stats.get( "errors" ) ) ) {
+                if ( logger.isDebugEnabled() ) {
+                    logger.debug( "notification {} already processed. not sending.", notification.getUuid()
);
+                }
+                return false;
+            }
+        }
+
+        else if(stats !=null && stats.get( "sent" )instanceof Long) {
+            if ( notification.getExpectedCount() == ( ( Long ) stats.get( "sent" ) + ( Long
) stats.get( "errors" ) ) ) {
+                if ( logger.isDebugEnabled() ) {
+                    logger.debug( "notification {} already processed. not sending.", notification.getUuid()
);
+                }
+                return false;
             }
-            return false;
         }
         if (notification.getCanceled() == Boolean.TRUE) {
             if (logger.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a737708f/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
index 91b94b2..775827e 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -16,24 +16,18 @@
  */
 package org.apache.usergrid.services.notifications;
 
-import org.apache.usergrid.persistence.*;
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.persistence.Query;
-import org.apache.usergrid.services.ServiceManagerFactory;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Receipt;
 import org.apache.usergrid.services.AbstractServiceIT;
-import org.springframework.beans.factory.annotation.Autowired;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -106,17 +100,17 @@ public abstract class AbstractServiceNotificationIT extends AbstractServiceIT
{
     }
 
     protected void checkStatistics(Notification notification, long sent,  long errors) throws
Exception{
-        Map<String, Long> statistics = null;
+        Map<String, Object> statistics = null;
         long timeout = System.currentTimeMillis() + 10000;
         while (System.currentTimeMillis() < timeout) {
             Thread.sleep(200);
             statistics = app.getEntityManager().get(notification.getUuid(), Notification.class).getStatistics();
-            if (statistics.get("sent")==sent && statistics.get("errors")==errors)
{
+            if ((Long)statistics.get("sent")==sent && (Long)statistics.get("errors")==errors)
{
                 break;
             }
         }
-        assertEquals(sent, statistics.get("sent").longValue());
-        assertEquals(errors, statistics.get("errors").longValue());
+        assertEquals(sent, ((Long)statistics.get("sent")).longValue());
+        assertEquals(errors, ((Long)statistics.get("errors")).longValue());
     }
 
 }


Mime
View raw message