You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/10/29 20:12:26 UTC

git commit: apns null reference issue

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o 610eb2da7 -> 77b8c5932


apns null reference issue


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

Branch: refs/heads/two-dot-o
Commit: 77b8c59325c7cfbd0c04be2a66dfce3ce55ab1bd
Parents: 610eb2d
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Oct 29 13:12:20 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Oct 29 13:12:20 2014 -0600

----------------------------------------------------------------------
 .../notifications/apns/APNsAdapter.java         | 37 ++++++++++----------
 .../notifications/apns/EntityPushManager.java   |  5 +--
 2 files changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/77b8c593/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
index 79a3b9e..a943bf5 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
@@ -64,6 +64,7 @@ public class APNsAdapter implements ProviderAdapter {
 
     private EntityManager entityManager;
     private EntityPushManager pushManager;
+    private LinkedBlockingQueue<SimpleApnsPushNotification> queue;
 
     public APNsAdapter(EntityManager entityManager, Notifier notifier){
         this.entityManager = entityManager;
@@ -76,13 +77,12 @@ public class APNsAdapter implements ProviderAdapter {
         try {
             CountDownLatch latch = new CountDownLatch(1);
             notification.setLatch(latch);
-            EntityPushManager pushManager = getPushManager(notifier);
-                addToQueue(pushManager, notification);
-                latch.await(10000,TimeUnit.MILLISECONDS);
-                if(notification.hasFailed()){
-                    // this is expected with a bad certificate (w/message: comes from failedconnectionlistener
-                    throw new ConnectionException("Bad certificate. Double-check your environment.",notification.getCause() != null ? notification.getCause() : new Exception("Bad certificate."));
-                }
+            addToQueue(notification);
+            latch.await(10000, TimeUnit.MILLISECONDS);
+            if (notification.hasFailed()) {
+                // this is expected with a bad certificate (w/message: comes from failedconnectionlistener
+                throw new ConnectionException("Bad certificate. Double-check your environment.", notification.getCause() != null ? notification.getCause() : new Exception("Bad certificate."));
+            }
                 notification.finished();
         } catch (Exception e) {
             notification.finished();
@@ -97,8 +97,8 @@ public class APNsAdapter implements ProviderAdapter {
         }
     }
 
-    private BlockingQueue<SimpleApnsPushNotification> addToQueue(PushManager<SimpleApnsPushNotification> pushManager, SimpleApnsPushNotification notification) throws InterruptedException {
-        BlockingQueue<SimpleApnsPushNotification> queue = pushManager.getQueue();
+    private BlockingQueue<SimpleApnsPushNotification> addToQueue(SimpleApnsPushNotification notification) throws Exception {
+        BlockingQueue<SimpleApnsPushNotification> queue = getPushManager(notifier).getQueue();
         queue.offer(notification,2500,TimeUnit.MILLISECONDS);
         return queue;
     }
@@ -107,9 +107,8 @@ public class APNsAdapter implements ProviderAdapter {
     public void sendNotification(String providerId, Object payload, Notification notification, TaskTracker tracker)
             throws Exception {
         APNsNotification apnsNotification = APNsNotification.create(providerId, payload.toString(), notification, tracker);
-        PushManager<SimpleApnsPushNotification> pushManager = getPushManager(notifier);
         try {
-            addToQueue(pushManager, apnsNotification);
+            addToQueue( apnsNotification);
             apnsNotification.messageSent();
         }catch (InterruptedException ie){
             apnsNotification.messageSendFailed(ie);
@@ -129,10 +128,12 @@ public class APNsAdapter implements ProviderAdapter {
     }
 
     private EntityPushManager getPushManager(Notifier notifier) throws ExecutionException {
-        if(pushManager != null &&  !pushManager.isStarted() && pushManager.isShutDown()){
+        if (pushManager == null || !pushManager.isStarted() || pushManager.isShutDown()) {
             PushManagerConfiguration config = new PushManagerConfiguration();
             config.setConcurrentConnectionCount(Runtime.getRuntime().availableProcessors() * 2);
-            EntityPushManager pushManager =  new EntityPushManager(notifier,entityManager, config);
+            queue = new LinkedBlockingQueue<SimpleApnsPushNotification>();
+
+            pushManager = new EntityPushManager(notifier, entityManager, queue, config);
             //only tested when a message is sent
             pushManager.registerRejectedNotificationListener(new RejectedAPNsListener());
             //this will get tested when start is called
@@ -144,10 +145,9 @@ public class APNsAdapter implements ProviderAdapter {
                 if (!pushManager.isStarted()) { //ensure manager is started
                     pushManager.start();
                 }
-            }catch(IllegalStateException ise){
-                logger.debug("failed to start",ise);//could have failed because its started
+            } catch (IllegalStateException ise) {
+                logger.debug("failed to start", ise);//could have failed because its started
             }
-            return pushManager;
         }
         return pushManager;
     }
@@ -189,8 +189,9 @@ public class APNsAdapter implements ProviderAdapter {
     @Override
     public void stop() {
         try {
-            if (!pushManager.isShutDown()) {
-                List<SimpleApnsPushNotification> notifications = pushManager.shutdown(3000);
+            EntityPushManager entityPushManager = getPushManager(notifier);
+            if (!entityPushManager.isShutDown()) {
+                List<SimpleApnsPushNotification> notifications = entityPushManager.shutdown(3000);
                 for (SimpleApnsPushNotification notification1 : notifications) {
                     try {
                         ((APNsNotification) notification1).messageSendFailed(new Exception("Cache Expired: Shutting down sender"));

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/77b8c593/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java
index d675081..c3790b8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java
@@ -32,6 +32,7 @@ import javax.net.ssl.SSLContext;
 import java.io.InputStream;
 import java.security.KeyStore;
 import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.LinkedBlockingQueue;
 
 /**
  * Store notifier within PushManager so it can be retrieved later.  Need this for the async token listener
@@ -40,8 +41,8 @@ public class EntityPushManager extends PushManager<SimpleApnsPushNotification> {
     private final Notifier notifier;
     private final EntityManager entityManager;
 
-    public EntityPushManager( Notifier notifier, EntityManager entityManager, PushManagerConfiguration configuration) {
-        super(getApnsEnvironment(notifier), getSSLContext(notifier), null, null, new LinkedBlockingDeque<SimpleApnsPushNotification>(), configuration, notifier.getName());
+    public EntityPushManager( Notifier notifier, EntityManager entityManager, LinkedBlockingQueue<SimpleApnsPushNotification> queue, PushManagerConfiguration configuration) {
+        super(getApnsEnvironment(notifier), getSSLContext(notifier), null, null, queue, configuration, notifier.getName());
         this.notifier = notifier;
         this.entityManager = entityManager;
     }