[TransWarp] New interfaces

Phillip J. Eby pje at telecommunity.com
Thu May 15 09:34:43 EDT 2003


At 03:40 PM 5/15/03 +0400, Oleg Broytmann wrote:
>    There is a number of components listed in the config file:
>
>[app]
>components = "db", "s_server", "ui", "httpd", "asyncore"
>
>component.db = "DataServer.DataServer"
>component.s_server = "ScenarioServer.ScenarioServer"
>component.ui = "UiServer.HtmlServer"
>component.httpd = "UiFrontend.BaseHTTPD"
>component.asyncore = "AsyncCore.AsyncCore"

Why not use the [Provide Utilities] section instead, e.g.:

[Provide Utilities]

myApp.interfaces.IUiFrontEnd = 
config.provideInstance('myApp.UiFrontEnd.BaseHTTPD')
...

(assuming 'myApp' is your package prefix, of course.)  In other words, why 
not just register these under the interface you want to find them by?


>    There is a loader that loads components and registers their interfaces 
> (the
>code that I posted was from the loader).

If you do as I suggest above, PEAK will instantiate and cache an instance 
of each component upon request for a utility of that instance.  The 
component that the config file was loaded into, will be used as the parent 
component of the created components.

So, if you want these components loaded somewhere besides the configuration 
root, just use config.loadConfigFile() to load a specific configuration 
file into a specific component.



>    Components try to lookup each other. For example, BaseHTTPD tries to 
> lookup
>UiServer by its IUiServer interface:
>
>class BaseHTTPD(Component):
>
>     implements(interfaces.IUiFrontend)
>
>     # link to UiServer
>     ui_server = binding.Once(
>         lambda s, d, a: config.findUtility(s, interfaces.IUiServer),
>         doc="HTML-based UI Server handling HTTP requests")
>
>    Now this fails - config.findUtility cannot find the interface because it
>was not registered.
>
>    BTW, AFAIU this can be shortened to
>
>     ui_server = binding.bindTo(interfaces.IUiServer)
>
>    right?

Yes.  Also, you can say 'binding.bindTo(interfaces.IUiServer, 
provides=interfaces.IUiServer)', if you want to then also publish the 
component to children of the current component, under that interface.  In 
fact, that's a common enough desire that I created a shortcut for 
it.  'binding.Acquire(foo)' is equivalent to 
'binding.bindTo(foo,provides=foo)'.




More information about the PEAK mailing list