[CalendarServer-changes] [8541] CalendarServer/trunk/calendarserver/push/applepush.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 16 13:15:38 PST 2012


Revision: 8541
          http://trac.macosforge.org/projects/calendarserver/changeset/8541
Author:   sagen at apple.com
Date:     2012-01-16 13:15:37 -0800 (Mon, 16 Jan 2012)
Log Message:
-----------
More APNS logging, reduce max time between reconnection attempts, prevent sending of empty tokens to APNS server.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/push/applepush.py

Modified: CalendarServer/trunk/calendarserver/push/applepush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/applepush.py	2012-01-16 19:08:11 UTC (rev 8540)
+++ CalendarServer/trunk/calendarserver/push/applepush.py	2012-01-16 21:15:37 UTC (rev 8541)
@@ -170,7 +170,8 @@
                 self.log_debug("Sending %d APNS notifications for %s" %
                     (numSubscriptions, key))
                 for token, guid in subscriptions:
-                    provider.sendNotification(token, key)
+                    if token and guid:
+                        provider.sendNotification(token, key)
 
 
 
@@ -272,6 +273,9 @@
         @type key: C{str}
         """
 
+        if not (token and key):
+            return
+
         try:
             binaryToken = token.replace(" ", "").decode("hex")
         except:
@@ -303,12 +307,15 @@
 
     def __init__(self, service):
         self.service = service
+        self.noisy = True
+        self.maxDelay = 30 # max seconds between connection attempts
 
     def clientConnectionMade(self):
+        self.log_warn("Connection to APN server made")
         self.service.clientConnectionMade()
 
     def clientConnectionLost(self, connector, reason):
-        # self.log_info("Connection to APN server lost: %s" % (reason,))
+        self.log_warn("Connection to APN server lost: %s" % (reason,))
         ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
 
     def clientConnectionFailed(self, connector, reason):
@@ -317,7 +324,12 @@
         ReconnectingClientFactory.clientConnectionFailed(self, connector,
             reason)
 
+    def retry(self, connector=None):
+        self.log_warn("Reconnecting to APN server")
+        ReconnectingClientFactory.retry(self, connector)
 
+
+
 class APNConnectionService(service.Service, LoggingMixIn):
 
     def __init__(self, host, port, certPath, keyPath, chainPath="",
@@ -370,12 +382,14 @@
         self.queue = []
 
     def startService(self):
-        self.log_debug("APNProviderService startService")
+        self.log_info("APNProviderService startService")
         self.factory = APNProviderFactory(self)
         self.connect(self.factory)
 
     def stopService(self):
-        self.log_debug("APNProviderService stopService")
+        self.log_info("APNProviderService stopService")
+        if self.factory is not None:
+            self.factory.stopTrying()
 
     def clientConnectionMade(self):
         # Service the queue
@@ -385,9 +399,13 @@
             queued = list(self.queue)
             self.queue = []
             for token, key in queued:
-                self.sendNotification(token, key)
+                if token and key:
+                    self.sendNotification(token, key)
 
     def sendNotification(self, token, key):
+        if not (token and key):
+            return
+
         # Service has reference to factory has reference to protocol instance
         connection = getattr(self.factory, "connection", None)
         if connection is None:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120116/a8408e58/attachment.html>


More information about the calendarserver-changes mailing list