Title: [commits] (bkirsch) [15302] fixes bug 10787 ConcurrentLoadItemError by explicitly defining a view to be used in the twisted reactor thread by mail clients.
Revision
15302
Author
bkirsch
Date
2007-09-06 16:18:12 -0700 (Thu, 06 Sep 2007)

Log Message

fixes bug 10787 ConcurrentLoadItemError by explicitly defining a view to be used in the twisted reactor thread by mail clients. There will be more refactoring post-Preview. r=vajda

Modified Paths

Diff

Modified: trunk/chandler/parcels/osaf/mail/base.py (15301 => 15302)

--- trunk/chandler/parcels/osaf/mail/base.py	2007-09-05 19:21:15 UTC (rev 15301)
+++ trunk/chandler/parcels/osaf/mail/base.py	2007-09-06 23:18:12 UTC (rev 15302)
@@ -293,6 +293,8 @@
         if __debug__:
             trace("testAccountSettings")
 
+        # The isOnline check is performed on the Main Thread
+        # so no need to pass in a view.
         if not Globals.mailService.isOnline():
             return
 
@@ -346,7 +348,9 @@
         #Overidden method
         self._getAccount()
 
-        if not Globals.mailService.isOnline():
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
+        if not Globals.mailService.isOnline(self.view):
             if self.statusMessages:
                 msg = constants.MAIL_PROTOCOL_OFFLINE % \
                               {"accountName": self.account.displayName}
@@ -461,7 +465,9 @@
 
         # In this case don't try to clean up the transport connection
         # but do reset the client variables
-        if self.shuttingDown or not Globals.mailService.isOnline() or \
+        # The isOnline check is performed in the Twisted thread so
+        # pass in a view.
+        if self.shuttingDown or not Globals.mailService.isOnline(self.view) or \
            self.factory is None:
             self._resetClient()
             return

Modified: trunk/chandler/parcels/osaf/mail/mailservice.py (15301 => 15302)

--- trunk/chandler/parcels/osaf/mail/mailservice.py	2007-09-05 19:21:15 UTC (rev 15301)
+++ trunk/chandler/parcels/osaf/mail/mailservice.py	2007-09-06 23:18:12 UTC (rev 15302)
@@ -68,10 +68,19 @@
     """
 
     def __init__(self, view):
-        self._view = view.repository.createView("Mail Service Read Only View", notify=False,
-                                                mergeFn=otherViewWins,
-                                                pruneSize=constants.MAILSERVICE_PRUNE_SIZE)
+        # The MailService uses the Main UI Repository View
+        self._view = view
 
+        # Mail Service clients (IMAP, SMTP, POP) use a shared view
+        # that is accessed only on the Twisted thread.
+        #
+        # Since the Twisted thread is async only one client will
+        # will be using the view at any given time.
+        self._clientView = view.repository.createView("Twisted Thread Client View",
+                                                      notify=False,
+                                                      mergeFn=otherViewWins,
+                                                      pruneSize=constants.MAILSERVICE_PRUNE_SIZE)
+
         self._started = False
         self._clientInstances = None
         self._mailWorker = None
@@ -84,6 +93,7 @@
 
         self._clientInstances = {"SMTP": {}, "IMAP": {}, "POP": {}}
 
+        # The MailWorker will create its own view
         self._mailWorker = MailWorker("MailWorker Thread", self._view.repository)
 
         #Start the mail worker thread
@@ -124,9 +134,18 @@
         schema.ns("osaf.pim", self._view).MailPrefs.isOnline = False
         self._view.commit()
 
-    def isOnline(self):
-        return schema.ns("osaf.pim", self._view).MailPrefs.isOnline
+    def isOnline(self, view=None):
+        """
+           A view should be passed when
+           the check for isOnline is not
+           performed on the Main UI Thread.
+        """
 
+        if view is None:
+            view = self._view
+
+        return schema.ns("osaf.pim", view).MailPrefs.isOnline
+
     def refreshMailServiceCache(self):
         """Refreshs the MailService Cache checking for
            any client instances that are associated with
@@ -176,14 +195,14 @@
         assert isinstance(account, Mail.SMTPAccount)
 
         if not fromCache:
-            return SMTPClient(self._view, account)
+            return SMTPClient(self._clientView, account)
 
         smtpInstances = self._clientInstances.get("SMTP")
 
         if account.itsUUID in smtpInstances:
             return smtpInstances.get(account.itsUUID)
 
-        s = SMTPClient(self._view, account)
+        s = SMTPClient(self._clientView, account)
         smtpInstances[account.itsUUID] = s
 
         return s
@@ -206,14 +225,15 @@
         assert isinstance(account, Mail.IMAPAccount)
 
         if not fromCache:
-            return IMAPClient(self._view, account, self._mailWorker)
+            return IMAPClient(self._clientView, account, self._mailWorker)
 
         imapInstances = self._clientInstances.get("IMAP")
 
         if account.itsUUID in imapInstances:
             return imapInstances.get(account.itsUUID)
 
-        i = IMAPClient(self._view, account, self._mailWorker)
+        i = IMAPClient(self._clientView, account, self._mailWorker)
+
         imapInstances[account.itsUUID] = i
 
         return i
@@ -235,14 +255,15 @@
         assert isinstance(account, Mail.POPAccount)
 
         if not fromCache:
-            return POPClient(self._view, account, self._mailWorker)
+            return POPClient(self._clientView, account, self._mailWorker)
 
         popInstances = self._clientInstances.get("POP")
 
         if account.itsUUID in popInstances:
             return popInstances.get(account.itsUUID)
 
-        i = POPClient(self._view, account, self._mailWorker)
+        i = POPClient(self._clientView, account, self._mailWorker)
+
         popInstances[account.itsUUID] = i
 
         return i

Modified: trunk/chandler/parcels/osaf/mail/mailworker.py (15301 => 15302)

--- trunk/chandler/parcels/osaf/mail/mailworker.py	2007-09-05 19:21:15 UTC (rev 15301)
+++ trunk/chandler/parcels/osaf/mail/mailworker.py	2007-09-06 23:18:12 UTC (rev 15302)
@@ -115,7 +115,7 @@
             return None
 
         if view is None:
-            view = self._repository.createView(self.getName(), 
+            view = self._repository.createView(self.getName(),
                                                notify=False,
                                                mergeFn=otherViewWins,
                                                pruneSize=constants.MAILWORKER_PRUNE_SIZE)

Modified: trunk/chandler/parcels/osaf/mail/smtp.py (15301 => 15302)

--- trunk/chandler/parcels/osaf/mail/smtp.py	2007-09-05 19:21:15 UTC (rev 15301)
+++ trunk/chandler/parcels/osaf/mail/smtp.py	2007-09-06 23:18:12 UTC (rev 15302)
@@ -168,6 +168,8 @@
         if __debug__:
             trace("testAccountSettings")
 
+        # The isOnline check is performed on the Main Thread
+        # so no need to pass in a view.
         if not Globals.mailService.isOnline():
             return self._resetClient()
 
@@ -193,28 +195,27 @@
         if __debug__:
             trace("_commit")
 
-        def _tryCommit():
-            try:
-                self.view.commit()
-            except VersionConflictError, e1:
-                #Place holder for commit rollback
-                trace(e1)
-                raise
-            except RepositoryError, e:
-                #Place holder for commit rollback
-                trace(e)
-                raise
+        try:
+            self.view.commit()
+        except VersionConflictError, e1:
+            #Place holder for commit rollback
+            trace(e1)
+            raise
+        except RepositoryError, e:
+            #Place holder for commit rollback
+            trace(e)
+            raise
 
-        d = threads.deferToThread(_tryCommit)
-        d.addCallbacks(lambda _: self._actionCompleted())
-        return d
+        return self._actionCompleted()
 
     def _actionCompleted(self):
         if __debug__:
             trace("_actionCompleted")
 
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
         if not self.displayed and not self.shuttingDown and \
-           Globals.mailService.isOnline() and not self.cancel:
+           Globals.mailService.isOnline(self.view) and not self.cancel:
             if self.mailMessage.itsItem.error:
                  key = "displaySMTPSendError"
             else:
@@ -260,7 +261,9 @@
             msg = self._getMailMessage(mailMessageUUID)
             mailStampOccurrence, masterMailStamp = getRecurrenceMailStamps(msg)
 
-            if self.mailMessage is not None or not Globals.mailService.isOnline():
+            # The isOnline check is performed in the Twisted thread
+            # so pass in a view.
+            if self.mailMessage is not None or not Globals.mailService.isOnline(self.view):
                 newMessage = masterMailStamp
 
                 try:
@@ -294,7 +297,9 @@
                     if __debug__:
                         trace("SMTPClient adding to the Queue message: %s" % mailMessageUUID)
 
-                if not Globals.mailService.isOnline():
+                # The isOnline check is performed in the Twisted thread
+                # so pass in a view.
+                if not Globals.mailService.isOnline(self.view):
                     setStatusMessage(constants.UPLOAD_OFFLINE % \
                                     {'accountName': self.account.displayName,
                                      'subject': mailStampOccurrence.subject})
@@ -356,7 +361,9 @@
         if __debug__:
             trace("_sendingMail")
 
-        if self.shuttingDown or not Globals.mailService.isOnline() or \
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
+        if self.shuttingDown or not Globals.mailService.isOnline(self.view) or \
            self.cancel:
             return self._resetClient()
 
@@ -413,7 +420,9 @@
         if __debug__:
             trace("_testSuccess")
 
-        if self.shuttingDown or not Globals.mailService.isOnline() or \
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
+        if self.shuttingDown or not Globals.mailService.isOnline(self.view) or \
            self.cancel:
             return self._resetClient()
 
@@ -425,7 +434,9 @@
         if __debug__:
             trace("_testFailure")
 
-        if self.shuttingDown or not Globals.mailService.isOnline() or \
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
+        if self.shuttingDown or not Globals.mailService.isOnline(self.view) or \
            self.cancel:
             return self._resetClient()
 
@@ -454,7 +465,9 @@
         if __debug__:
             trace("_mailSuccessCheck")
 
-        if self.shuttingDown or not Globals.mailService.isOnline() or \
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
+        if self.shuttingDown or not Globals.mailService.isOnline(self.view) or \
            self.cancel:
             return self._resetClient()
 
@@ -491,7 +504,9 @@
         if __debug__:
             trace("_mailSomeFailed")
 
-        if self.shuttingDown or not Globals.mailService.isOnline() or \
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
+        if self.shuttingDown or not Globals.mailService.isOnline(self.view) or \
            self.cancel:
             return self._resetClient()
 
@@ -517,7 +532,9 @@
         if __debug__:
             trace("_mailFailure")
 
-        if self.shuttingDown or not Globals.mailService.isOnline() or \
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
+        if self.shuttingDown or not Globals.mailService.isOnline(self.view) or \
            self.cancel:
             return self._resetClient()
 
@@ -560,7 +577,9 @@
         if __debug__:
             trace("displayedRecoverableSSLErrorDialog")
 
-        if not dryRun and (self.shuttingDown or not Globals.mailService.isOnline() or \
+        # The isOnline check is performed in the Twisted thread
+        # so pass in a view.
+        if not dryRun and (self.shuttingDown or not Globals.mailService.isOnline(self.view) or \
            self.cancel):
             return self._resetClient()
 




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to