Python Manual User Manual

Page of 124
Detecting a Failure
61
id = service.reset()
self.processResponse(self.resetResponse,id)
print "request",binding.agentIdentity(),id
def resetResponse(self):
print "result"
In addition to "
conversationId()
" the member function "
currentResponse()
" is also
available. This member function returns an object providing both the "
conversationId()
" and
"
sender()
" member functions. If you need the service binding object for the service agent who sent
the response, you can perform a lookup against the service registry using the service address provided
by "
sender()
". Note though that you shouldn’t assume that the service binding object will be avail-
able as the remote service may have been withdrawn by the time you make your query.
Detecting a Failure
If you send a service request to a service agent and you need to detect if a failure occurs, you will need
to have registered a callback using the "
processFailure()
" member function. A failure may oc-
cur due to the service not supplying a method to handle the request you made, an incorrect number of
arguments being supplied, an error within the method being called or because the remote service agent
was withdrawn before a response was received.
When a failure does occur, the details of the failure can be obtained in a number of ways. If the callback
you provide doesn’t take any arguments, you can obtain a failure object detailing the error which oc-
curred by calling the "
currentFailure()
" member function. The member functions provided by
the failure object are "
error()
", "
description()
", "
origin()
" and "
details()
". The con-
versation id associated with the request which failed can be obtained using the member function
"
conversationId()
".
Of the member functions provided by the failure object, the "
error()
" member function returns an
integer error code. The "
description()
" member function returns a text description of the error.
The "
origin()
" member function returns a string which in some way identifies the origin of the er-
ror and "
detail()
" may contain as text, extra details relating to the error which has occurred.
class Client(netsvc.Service):
def __init__(self,name):
netsvc.Service.__init__(self,"","")
service = self.serviceEndPoint("SMS")
if service:
id = service.uptime()
self.processResponse(self.uptimeResponse,id)
self.processFailure(self.uptimeFailure,id)
def uptimeResponse(self,result):
print result
def uptimeFailure(self):
id = self.conversationId()
failure = self.currentFailure()