Python Manual User Manual

Page of 124
Service Requests
70
that the result is returned immediately. Note that since the response is immediate, you can’t call a meth-
od which itself would try and use a delayed response.
class DatabaseProxy(netsvc.Service):
def __init__(self,name="database-proxy")
netsvc.Service.__init__(self,name):
self.exportMethod(self.tables)
self._active = {}
def tables(self):
service = netsvc.LocalService("database")
return service.execute("show tables")
As with a service endpoint object, if there is more than one service agent with the same name, the first
one found will be used. The only restriction is that candidate service agents will only come from the
set of service agents in the same process which are also implemented in Python. If a request is made
against an instance of
LocalService
and no service agent could be found, an exception of type
ServiceUnavailable
will be raised. To avoid this, you can also perform a truth test against the
object.
Although the request is channelled through directly to the service instance, it is still not possible to call
methods of the service which haven’t been exported. When this occurs, an exception of type
Serv-
iceFailure
is raised where the origin is set to "
netsvc
" and the error code is set to
"
SERVER_METHOD_UNAVAILABLE
". Any other errors raised by the method being called are simi-
larly indicated using the
ServiceFailure
exception. Note that each of the attributes of the failure,
ie., the error code, description, origin and details, are available using member variables and not mem-
ber functions as is the case with a failure response object.
If the member function making the request is servicing a request from another service, it may be ap-
propriate to translate the exceptions into different types of failure responses. As is, the exceptions
would translate into a failure response with the same details. This may be confusing for example if it
were an exception indicating that a method was unavailable. The remote service making the request
would errornously think that it had called an invalid method when it was actually the implementation
of the method which it had called which had done the wrong thing.
Note that the LocalService class is being deprecated and will most likely not be available in a future
version of OSE. You are therefore advised not to write any new code using it and change existing code
to use the full messaging system features.