Service Agents

Group Announcements

If a service agent subscribes to the service registry using a specific service group, it will be notified when any service joins or leaves that group. Notice that a service has left a particular group will also be be notified when the service is withdrawn and the service hadn’t explicitly left the group before hand. The member functions relating to service group subscriptions are "subscribeService- Group()" and "unsubscribeServiceGroup()".

Subscription to a service group is most often used as a way of finding out what services exist which perform a certain function. As an example, service agents which provide an interface to equipment in a telecommunications network could join a particular group. A service which has the task of monitor- ing alarms generated by the same equipment could then subscribe to that service group and be notified about each equipment agent. Knowing about each equipment agent, the alarm monitor could then sub- scribe to any alarm reports generated by the equipment agents.

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

netsvc.Service.__init__(self,"equipment-monitor") self.subscribeServiceGroup(self.announce,"equipment-agents")

def announce(self,binding,group,status): if status == netsvc.SERVICE_AVAILABLE:

self.monitorReports(self.alarm,binding,"alarm.*") else:

self.ignoreReports(binding)

def alarm(self,service,subject,content): print subject,content

By using a service group it is therefore possible to make an application respond dynamically to the in- troduction of new service agents. In the case of the equipment alarm monitor for a telecommunications network, it would not be necessary to hardwire in details of the equipment. Instead, when adding a new piece of a equipment, the service agent providing an interface to that equipment need only add itself to the appropriate service group.

Such a mechanism could also be used to monitor alarms raised as a result of problems in the application itself and need not be alarms generated by some piece of equipment. This mechanism could therefore also be used as the basis of an application health monitoring system.

Service Lookup

The ability to subscribe to the service registry provides a means of tracking the existance of service agents over time. The alternative to subscribing to the service registry to find out about available serv- ices, is to do a lookup against the service registry. Performing a lookup will tell you immediately what service agents exist at that particular point in time. No subscription will be registered when doing a lookup though, so if you need to know when a service agent is subsequently withdrawn it still may be appropriate to subscribe to the registry using the address of the specific service agent you use.

44

Page 44
Image 44
Python Python Manual, 7.0pl5 manual Group Announcements, Service Lookup