Service Reports

subject corresponding to a log channel, the log messages on that log channel will be intercepted and published. This can be useful as a remote debugging mechanism and will not unnecessarily load the process as information is only being captured and published when it is actually required.

Existence of Publishers

When a subscription to a service is made, if the service holds any cached reports with a subject match- ing the subscription, the subscriber will receive them immediately. If however there were no such re- ports, the subscriber will not receive any reports until some are published having a subject which matched its subscription. Even when there are reports which can be sent back immediately, if there are reports against multiple subjects, there is no guarantee as to which order they will be received in.

As a consequence, using the reception of a report as an indicator that a service has become available is not a good approach to take. This is because a report may not be received until some time after the service became available and the subscription accepted. Further, there is no indication when the service is no longer available.

One way as previously described of knowing when a service becomes available or when it is with- drawn, is to subscribe to the service registry. Although this will work, if you have restricted the service audience of your service agent, it will also possibly tell you about services outside of the scope of what you can subscribe to.

To avoid this difficulty, the member function "handlePublisherNotification()" is provid- ed. This member function can be overridden in your service agent and will be called only when a sub- scription has been matched up and accepted by the service being subscribed to. Note that this notification will only occur for the first subscription against a particular service agent.

This member function will also be called to acknowledge withdrawal of the last subscription against a particular service agent, or when a service agent to which you were subscribed has been withdrawn.

class Subscriber(netsvc.Service): def __init__(self):

netsvc.Service.__init__(self) self.monitorReports("publisher","*")

def handlePublisherNotification(self,notification): name = notification.publisher().serviceName() identity = notification.publisher().agentIdentity() publisher = "(%s/%s)" % (‘name‘,identity)

if notification.status() == SERVICE_AVAILABLE: print "%s AVAILABLE" % publisher

else:

print "%s WITHDRAWN" % publisher

Knowledge of when a subscription has been accepted or when the service agent subscribed to has been withdrawn can be useful when there is more than once service agent with the same name, and it is nec-

54

Page 54
Image 54
Python Python Manual, 7.0pl5 manual Existence of Publishers