Changed notification object to accept both Integers and Long in the map.
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 javax.xml.bind.annotation.XmlRootElement;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.apache.usergrid.persistence.*;
+import javax.xml.bind.annotation.XmlRootElement;
+
+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 @@
/** 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 @@
}
@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" ) );
+ }
}
}
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 @@
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;
}
- 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;
+ }
}
if (notification.getCanceled() == Boolean.TRUE) {
if (logger.isDebugEnabled()) {
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 @@
}
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());
}
}