Example #1
0
 def acquireNew(self, **kwargs):
     timeout = kwargs.pop("timeout", self.api().timeout)
     kw = {"timeout":timeout}
     if "purge" in kwargs:
         kw["purge"] = kwargs["purge"]
     tId = self.tId()
     result = self.api().ipc.getTransactionManager().acquireNew(tId, **kw)
     result = ApiTransportResponse.decode(result)
     #    Now either raise or return the result:
     if isinstance(result, Exception):
         raise result
     return result
Example #2
0
 def _executeAction(self):
     ns = self.namespace
     args = self.args()
     kwargs = self.kwargs()
     ipc = self.ipc
     transactionManager = ipc.getTransactionManager()
     data = ApiTransportItem(ns, args, kwargs)
     #    Now decide how to handle the call - synchronous is different to asynchronous.
     data.async((self.sync == eSync.SYNCHRONOUS))
     callback = self.callback
     if self.sync == eSync.SYNCHRONOUS:
         #    Send the data:
         solicited = self.solicited
         wrapper = ApiCallbackWrapper.callback(callback)
         tId = ipc.sendData(data, solicited=solicited, callback=wrapper)
         dId = self._debugSync(tId=tId, timeout=self.timeout, data=data, solicited=solicited, callback=wrapper)
         #    For solicited calls, we must wait for the response - unless a callback is set.
         if solicited:
             if callback == None:
                 result = transactionManager.acquireNew(tId, timeout=self.timeout, purge=True)
                 result = ApiTransportResponse.decode(result)
                 self._debugResult(dId, result)
                 if isinstance(result, Exception):
                     raise result
                 else:
                     return result
             else:
                 self._startCallbackTimeoutTimer(dId, tId, transactionManager)
             return AsyncResult(self, tId)  #    WTF - this is synchronous ?!?!!
         #    By definition, unsolicited calls are fire-and-forget, so no return value necessary.
     else:
         #    Send the data:
         solicited = self.solicited
         wrapper = ApiCallbackWrapper.callback(callback)
         tId = ipc.sendData(data, solicited, callback=wrapper)
         dId = ApiAction._dId.next()
         self._startCallbackTimeoutTimer(dId, tId, transactionManager)
         #    Now return an object which we can use to later wait for the response.
         result = AsyncResult(self, tId)
         self._debugAsync(dId, result, timeout=self.timeout, data=data, solicited=solicited, callback=wrapper)
         return result
Example #3
0
 def _cb(self, tId, result):
     originalResult = result
     result = ApiTransportResponse.decode(result)
     ApiCallbackWrapper.logger.debug("Decoded %(T)s." % {"T":tId, "O":originalResult, "N":result})
     #    Now call the original callback:
     return self._callback(tId, result)