Proposed system for subcomponent flexibility
Many Kamaelia components need to create their own subcomponents at run-time, e.g. my HTTP client spawns a TCPClient to connect to the server. However, this can cancel out much of the flexibility that a component-based architecture provides. As an alternative to hard-coding the class of each subcomponent, I propose that every subcomponent should be created from by a function provided as an argument at that components creation.
For example, in SingleShotHTTPClient:
For example, in SingleShotHTTPClient:
def __init__(self, starturl, postbody = "", connectionclass = TCPClient):And whenever a TCPClient was created in the old code, connectionclass is now called with the same parameters. The possibilities added by this are great:
...
self.connectionclass = connectionclass
- for debugging, TCPClient could be replaced with a local console masquerading as a TCP connection.
- TCPClient could also be replaced by a SOCKSTCPClient allowing it to go via a SOCKS proxy.
- for logging purposes, connectionclass could be a wrapper function (rather than a class) that wrote the host addresses accessed to a file before spawning and returning a TCPClient
- etc.
Labels: kamaelia
0 Comments:
Post a Comment
<< Home