[Twisted-Python] Questions regarding serviceCollection and Interfaces.
itamar at itamarst.org
Tue Jul 5 09:50:29 EDT 2005
On Tue, 2005-07-05 at 15:16 +0300, kgi wrote:
> But in this case, it looks like we're actually instantiating an
> interface class.
> I can't grok what this "means", especially in light of the fact that there
> is "MultiService" below it that implements IServiceCollection.
This is interface adaptation, see
http://twistedmatrix.com/projects/core/documentation/howto/components.html for an expalantion.
> 3. What do I gain by using a serviceCollection over an application as the
> serviceParent of a TCPServer? Come to think of it, what did I gain in the
> first place with setServiceParent()?
Services are setup as a tree; the application is the root of the tree.
Services let you organize your code as pluggable self-contained parts
that get startup and shutdown events. Of course, for a simple TCP server
that doesn't give you much.
> 4. Lastly, there are lots of examples floating around that describe
> how each Protocol example can reference its own Factory in order for
> connections to be able to talk to other connections (for example, in
> the chat server example). However, what approach should I take when I
> have a single server with multiple Protocols?
> For example, consider a simple cache: I have a server which accepts
> TCP connections from lots of clients, and handles queries from
> these clients. The server actually gets information from an
> upstream server, but caches the results that it has already seen.
> In this case in the server I need a Protocol/TCPServer server to
> handle the multiple clients, and a single Protocol/connectTCP
> client for the upstream connection. However, it's not clear to me
> how I would transfer the data from the lineReceived() method of the
> server Protocol to the sendLine() method of the client Protocol,
> since each Protocol can see its own Factory, but not the Factory of
> the other Protocol.
myServerFactory.clientFactory = myClientFactory
# and now server Protocol instances can do self.factory.clientFactory
More information about the Twisted-Python