[Opensrf-commits] r1331 - trunk/src/python/osrf

svn at svn.open-ils.org svn at svn.open-ils.org
Tue May 20 15:43:16 EDT 2008


Author: erickson
Date: 2008-05-20 15:43:13 -0400 (Tue, 20 May 2008)
New Revision: 1331

Modified:
   trunk/src/python/osrf/net.py
Log:
added new disconnected exception.  added some error condition logging.  no longer disconnecting on network handle clear, because parent process may be using the handle.

Modified: trunk/src/python/osrf/net.py
===================================================================
--- trunk/src/python/osrf/net.py	2008-05-20 19:41:55 UTC (rev 1330)
+++ trunk/src/python/osrf/net.py	2008-05-20 19:43:13 UTC (rev 1331)
@@ -33,6 +33,7 @@
 
 
 
+
 class XMPPNoRecipient(osrf.ex.OSRFException):
     ''' Raised when a message was sent to a non-existent recipient 
         The recipient is stored in the 'recipient' field on this object
@@ -41,6 +42,9 @@
         osrf.ex.OSRFException.__init__(self, 'Error communicating with %s' % recipient)
         self.recipient = recipient
 
+class XMPPNoConnection(osrf.ex.OSRFException):
+    pass
+
 def set_network_handle(handle):
     """ Sets the thread-specific network handle"""
     THREAD_SESSIONS[threading.currentThread().getName()] = handle
@@ -53,8 +57,10 @@
     ''' Disconnects the thread-specific handle and discards it '''
     handle = THREAD_SESSIONS.get(threading.currentThread().getName())
     if handle:
-        handle.disconnect()
+        osrf.log.log_internal("clearing network handle %s" % handle.jid.as_utf8())
+        #handle.disconnect()
         del THREAD_SESSIONS[threading.currentThread().getName()]
+        return handle
 
 class NetworkMessage(object):
     """Network message
@@ -82,7 +88,7 @@
             else:
                 self.sender = message.get_from().as_utf8()
             if message.xmlnode.hasProp('osrf_xid'):
-                self.xid = message.xmlnode
+                self.xid = message.xmlnode.prop('osrf_xid')
             else:
                 self.xid = ''
         else:
@@ -182,6 +188,16 @@
         self.queue.append(NetworkMessage(stanza))
         return True
 
+    def stream_closed(self, stream):
+        osrf.log.log_debug("XMPP Stream closing...")
+
+    def stream_error(self, err):
+        osrf.log.log_error("XMPP Stream error: condition: %s %r"
+            % (err.get_condition().name,err.serialize()))
+
+    def disconnected(self):
+        osrf.log.log_internal('XMPP Disconnected')
+
     def recv(self, timeout=120):
         """Attempts to receive a message from the network.
 
@@ -199,10 +215,17 @@
         if len(self.queue) == 0:
             while (forever or timeout >= 0) and len(self.queue) == 0:
                 starttime = time.time()
-                act = self.get_stream().loop_iter(timeout)
+
+                stream = self.get_stream()
+                if not stream:
+                   raise XMPPNoConnection('We lost our server connection...') 
+
+                act = stream.loop_iter(timeout)
                 endtime = time.time() - starttime
+
                 if not forever:
                     timeout -= endtime
+
                 osrf.log.log_internal("exiting stream loop after %s seconds. "
                     "act=%s, queue size=%d" % (str(endtime), act, len(self.queue)))
 



More information about the opensrf-commits mailing list