[CalendarServer-changes] [9109] CalendarServer/trunk/calendarserver/push

source_changes at macosforge.org source_changes at macosforge.org
Fri Apr 13 16:24:42 PDT 2012


Revision: 9109
          http://trac.macosforge.org/projects/calendarserver/changeset/9109
Author:   sagen at apple.com
Date:     2012-04-13 16:24:42 -0700 (Fri, 13 Apr 2012)
Log Message:
-----------
Adds support for subscribing to any AMP push id (via special id, "any")

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/push/amppush.py
    CalendarServer/trunk/calendarserver/push/test/test_amppush.py

Modified: CalendarServer/trunk/calendarserver/push/amppush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/amppush.py	2012-04-13 22:45:48 UTC (rev 9108)
+++ CalendarServer/trunk/calendarserver/push/amppush.py	2012-04-13 23:24:42 UTC (rev 9109)
@@ -138,15 +138,19 @@
                 yield self.sendNotification(token, id)
 
 
-class AMPPushNotifierProtocol(amp.AMP):
+class AMPPushNotifierProtocol(amp.AMP, LoggingMixIn):
 
     def __init__(self, service):
         super(AMPPushNotifierProtocol, self).__init__()
         self.service = service
         self.subscriptions = {}
+        self.any = None
 
     def subscribe(self, token, id):
-        self.subscriptions[id] = token
+        if id == "any":
+            self.any = token
+        else:
+            self.subscriptions[id] = token
         return {"status" : "OK"}
     SubscribeToID.responder(subscribe)
 
@@ -160,9 +164,12 @@
 
     def notify(self, token, id):
         if self.subscribedToID(id) == token:
+            self.log_debug("Sending notification for %s to %s" % (id, token))
             return self.callRemote(NotificationForID, id=id)
 
     def subscribedToID(self, id):
+        if self.any is not None:
+            return self.any
         return self.subscriptions.get(id, None)
 
     def connectionLost(self, reason=None):

Modified: CalendarServer/trunk/calendarserver/push/test/test_amppush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/test/test_amppush.py	2012-04-13 22:45:48 UTC (rev 9108)
+++ CalendarServer/trunk/calendarserver/push/test/test_amppush.py	2012-04-13 23:24:42 UTC (rev 9109)
@@ -47,10 +47,14 @@
         client2 = TestProtocol(service)
         client2.subscribe("token2", "/CalDAV/localhost/user01/")
 
+        client3 = TestProtocol(service)
+        client3.subscribe("token3", "any")
+
         service.addSubscriber(client1)
         service.addSubscriber(client2)
+        service.addSubscriber(client3)
 
-        self.assertEquals(len(service.subscribers), 2)
+        self.assertEquals(len(service.subscribers), 3)
 
         self.assertTrue(client1.subscribedToID("/CalDAV/localhost/user01/"))
         self.assertTrue(client1.subscribedToID("/CalDAV/localhost/user02/"))
@@ -59,13 +63,23 @@
         self.assertTrue(client2.subscribedToID("/CalDAV/localhost/user01/"))
         self.assertFalse(client2.subscribedToID("/CalDAV/localhost/user02/"))
 
+        self.assertTrue(client3.subscribedToID("/CalDAV/localhost/user01/"))
+        self.assertTrue(client3.subscribedToID("/CalDAV/localhost/user02/"))
+        self.assertTrue(client3.subscribedToID("/CalDAV/localhost/user03/"))
+
         service.enqueue("update", "CalDAV|user01")
         self.assertEquals(len(client1.history), 0)
+        self.assertEquals(len(client2.history), 0)
+        self.assertEquals(len(client3.history), 0)
         clock.advance(1)
         self.assertEquals(client1.history, [(NotificationForID, {'id': '/CalDAV/localhost/user01/'})])
         self.assertEquals(len(client2.history), 0)
+        self.assertEquals(len(client3.history), 0)
         clock.advance(3)
         self.assertEquals(client2.history, [(NotificationForID, {'id': '/CalDAV/localhost/user01/'})])
+        self.assertEquals(len(client3.history), 0)
+        clock.advance(3)
+        self.assertEquals(client3.history, [(NotificationForID, {'id': '/CalDAV/localhost/user01/'})])
 
         client1.reset()
         client2.reset()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120413/17cd6c50/attachment.html>


More information about the calendarserver-changes mailing list