[PEAK] runIni => ZConfig revisited

Phillip J. Eby pje at telecommunity.com
Fri Nov 14 14:58:22 EST 2003


At 11:47 AM 11/14/03 -0800, John Landahl wrote:
>Ideally the application would have a) one component periodically 
>downloading configuration updates from a central server, b) 
>publish/subscribe on configuration keys.  Components could then subscribe 
>to the configuration keys they care about, receive notifications when 
>changes are made, and do whatever is necessary with the information, such 
>as resetting their work schedule, changing the location of the server they 
>talk to, change the template of an external command they run, etc.

You could possibly do this by creating an IComponentKey implementation that 
handled the subscription.  e.g.

class SubscribeTo:

     protocols.advise( instancesProvide = [binding.IComponentKey] )

     def __init__(self,key,attr):
         self.key = adapt(key,binding.IComponentKey)
         self.attr = attr

     def findComponent(self,comp,default=NOT_GIVEN):
         # subscribe a listener function for self.key that
         # will do 'setattr(comp,attr,value)' whenever the
         # function is called by the subscriber...
         return self.key.findComponent(comp,default)


...then, to use it...

class Something(binding.Component):

     thing = binding.Obtain(SubscribeTo(PropertyName('whatever'), 'thing'))


Obviously, I have left some things as an exercise for the reader.  :)

Also, it would probably be nicer to use, if component keys were told the 
"name" they're being looked up under.  Perhaps I could change the interface 
to supply that info.

Another open issue is that other bindings that depend upon the configured 
value/component will not be updated.




More information about the PEAK mailing list