Ejemplo n.º 1
0
 def CloseQueue(self, key, c=None, discarded=None, permanent=False):
     """
     Try to close or delete a persistent queue opened at server side
     :param key: An ASCII string for identifying a queue at server side
     :param c: A callback for tracking returning error code, which can be one of QUEUE_OK, QUEUE_DEQUEUING, and so on
     :param permanent: true for deleting a queue file, and false for closing a queue file
     :param discarded A callback for tracking socket close or request cancel event
     :return: true for sending the request successfully, and false for failure
     """
     if not key:
         key = ''
     buffer = CScopeUQueue.Lock().SaveAString(key).SaveBool(permanent)
     ok = None
     if not c:
         ok = self.SendRequest(CAsyncQueue.idClose, buffer, None, discarded)
     else:
         ok = self.SendRequest(CAsyncQueue.idClose, buffer,
                               lambda ar: c(ar.LoadInt()), discarded)
     CScopeUQueue.Unlock(buffer)
     return ok
Ejemplo n.º 2
0
 def Enqueue(self, key, idMessage, q, e=None):
     """
     Enqueue a message into a queue file identified by a key
     :param key: An ASCII string for identifying a queue at server side
     :param idMessage: A unsigned short number to identify a message
     :param q: an instance of SPA.CUQueue containing a message
     :param e: A callback for tracking returning index
     :return: true for sending the request successfully, and false for failure
     """
     if not key:
         key = ''
     buffer = CScopeUQueue.Lock().SaveAString(key).SaveUShort(idMessage)
     if q:
         buffer.Push(q.IntenalBuffer, q.GetSize())
     ok = None
     if not e:
         ok = self.SendRequest(CAsyncQueue.idEnqueue, buffer, None)
     else:
         ok = self.SendRequest(CAsyncQueue.idEnqueue, buffer,
                               lambda ar: e(ar.LoadULong()))
     CScopeUQueue.Unlock(buffer)
     return ok
Ejemplo n.º 3
0
 def StartQueueTrans(self, key, qt=None, discarded=None):
     """
     Start enqueuing messages with transaction style. Currently, total size of queued messages must be less than 4 G bytes
     :param key: An ASCII string for identifying a queue at server side
     :param qt: A callback for tracking returning error code, which can be one of QUEUE_OK, QUEUE_TRANS_ALREADY_STARTED, and so on
     :param discarded A callback for tracking socket close or request cancel event
     :return: true for sending the request successfully, and false for failure
     """
     if not key:
         key = ''
     buffer = CScopeUQueue.Lock().SaveAString(key)
     ok = None
     cq = self.AttachedClientSocket.ClientQueue
     if cq.Available:
         cq.StartJob()
     if not qt:
         ok = self.SendRequest(CAsyncQueue.idStartTrans, buffer, None,
                               discarded)
     else:
         ok = self.SendRequest(CAsyncQueue.idStartTrans, buffer,
                               lambda ar: qt(ar.LoadInt()), discarded)
     CScopeUQueue.Unlock(buffer)
     return ok
Ejemplo n.º 4
0
 def Dequeue(self, key, d, timeout=0):
     """
     Dequeue messages from a persistent message queue file at server side in batch
     :param key: An ASCII string for identifying a queue at server side
     :param d: A callback for tracking data like remaining message count within a server queue file, queue file size in bytes, message dequeued within this batch and bytes dequeued within this batch
     :param timeout: A time-out number in milliseconds
     :return: true for sending the request successfully, and false for failure
     """
     if not key:
         key = ''
     with self._csQ_:
         self._dDequeue_ = d
         self._keyQueue_ = key
     buffer = CScopeUQueue.Lock().SaveAString(key).SaveUInt(timeout)
     ok = None
     if not d:
         ok = self.SendRequest(CAsyncQueue.idDequeue, buffer, None)
     else:
         ok = self.SendRequest(
             CAsyncQueue.idDequeue, buffer,
             lambda ar: d(ar.LoadULong(), ar.LoadULong(), ar.LoadUInt(),
                          ar.LoadUInt()))
     CScopeUQueue.Unlock(buffer)
     return ok
Ejemplo n.º 5
0
 def EndQueueTrans(self, rollback=False, qt=None, discarded=None):
     """
     End enqueuing messages with transaction style. Currently, total size of queued messages must be less than 4 G bytes
     :param rollback: true for rollback, and false for committing
     :param qt: A callback for tracking returning error code, which can be one of QUEUE_OK, QUEUE_TRANS_NOT_STARTED_YET, and so on
     :param discarded A callback for tracking socket close or request cancel event
     :return: true for sending the request successfully, and false for failure
     """
     buffer = CScopeUQueue.Lock().SaveBool(rollback)
     ok = None
     if not qt:
         ok = self.SendRequest(CAsyncQueue.idEndTrans, buffer, None,
                               discarded)
     else:
         ok = self.SendRequest(CAsyncQueue.idEndTrans, buffer,
                               lambda ar: qt(ar.LoadInt()), discarded)
     cq = self.AttachedClientSocket.ClientQueue
     if cq.Available:
         if rollback:
             cq.AbortJob()
         else:
             cq.EndJob()
     CScopeUQueue.Unlock(buffer)
     return ok