[Twisted-Python] Cascading services (passing events through connected services)

Hi, I'm currently trying to implement the JXTA standard (http://www.jxta.org) in Python using twisted (because it seems to be the right choice). I've implemented the basic parts that are not network related, that is, not much ;) To make a correct JXTA peer (well designed to be modular and to be able to add services), I have cascade several services (I think they should be services, but I can be wrong, I'm a real beginner with Twisted). For instance: network -> TCP transport layer service -> endpoint service -> some other high level services -> endpoint service -> TCP transport layer (may not be the same as the first one). Is there a sample somewhere that does something like this ? Each time an event is sent to a listener (the TCP transport layer, the endpoint, ...) that acts upon it. I've tried to find some samples over the Internet, but perhaps someone has a pointer to help me ? Matthieu -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher

On 09:38 pm, matthieu.brucher@gmail.com wrote:
I'm currently trying to implement the JXTA standard (http://www.jxta.org) in Python using twisted (because it seems to be the right choice). I've implemented the basic parts that are not network related, that is, not much ;)
Of course it's the right choice. Twisted is *awesome* ;-).
network -> TCP transport layer service -> endpoint service -> some other high level services -> endpoint service -> TCP transport layer
You use the word "service" a lot here and I'm not sure I understand it. There are, unfortunately, a dozen or so things you could mean by it.
Is there a sample somewhere that does something like this ? Each time an event is sent to a listener (the TCP transport layer, the endpoint, ...) that acts upon it. I've tried to find some samples over the Internet, but perhaps someone has a pointer to help me ?
Assuming I do understand what all those "service" and "->"s mean in the above text, all you need to do is to 1) have some objects 2) keep references between them to other objects 3) call methods on the relevant objects when the relevant things happen Quite often, people somehow arrive at the incorrect conclusion that because twisted is event-driven, it has some magic "event" mechanism you have to use to get different pieces of code to talk to each other. Quite the opposite; the whole point of Twisted is to reduce event-driven programming to just regular Python method calls. It may help, if you need to relay messages from one connected Protocol object to another, that Protocol objects have a reference to their factory, and you can easily keep a list of "all connections" on that factory. This is actually two of our FAQs - have a look at this one and the next one: http://tinyurl.com/6hpfa7

2008/5/7 <glyph@divmod.com>:
On 09:38 pm, matthieu.brucher@gmail.com wrote:
I'm currently trying to implement the JXTA standard (http://www.jxta.org) in Python using twisted (because it seems to be the right choice). I've implemented the basic parts that are not network related, that is, not much ;)
Of course it's the right choice. Twisted is *awesome* ;-).
network -> TCP transport layer service -> endpoint service -> some other high level services -> endpoint service -> TCP transport layer
You use the word "service" a lot here and I'm not sure I understand it. There are, unfortunately, a dozen or so things you could mean by it.
Yes, I know, it is not perfectly clear in my head as well, I have to play with twisted and JXTA a little more to have a clear picture.
Is there a sample somewhere that does something like this ? Each time an
event is sent to a listener (the TCP transport layer, the endpoint, ...) that acts upon it. I've tried to find some samples over the Internet, but perhaps someone has a pointer to help me ?
Assuming I do understand what all those "service" and "->"s mean in the above text, all you need to do is to
1) have some objects 2) keep references between them to other objects 3) call methods on the relevant objects when the relevant things happen
Quite often, people somehow arrive at the incorrect conclusion that because twisted is event-driven, it has some magic "event" mechanism you have to use to get different pieces of code to talk to each other. Quite the opposite; the whole point of Twisted is to reduce event-driven programming to just regular Python method calls.
That's what I thought reading the tutorial.
It may help, if you need to relay messages from one connected Protocol object to another, that Protocol objects have a reference to their factory, and you can easily keep a list of "all connections" on that factory. This is actually two of our FAQs - have a look at this one and the next one:
Excallent ! Thanks a lot for this, it will help me a lot ! Matthieu -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
participants (2)
-
glyph@divmod.com
-
Matthieu Brucher