Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / pb / cache_receiver.py
1 #!/usr/bin/env python
2
3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
5
6 from twisted.application import service, internet
7 from twisted.internet import reactor
8 from twisted.spread import pb
9 import cache_classes
10
11 class Receiver(pb.Root):
12     def remote_takePond(self, pond):
13         self.pond = pond
14         print "got pond:", pond # a DuckPondCache
15         self.remote_checkDucks()
16     def remote_checkDucks(self):
17         print "[%d] ducks: " % self.pond.count(), self.pond.getDucks()
18     def remote_ignorePond(self):
19         # stop watching the pond
20         print "dropping pond"
21         # gc causes __del__ causes 'decache' msg causes stoppedObserving
22         self.pond = None
23     def remote_shutdown(self):
24         reactor.stop()
25
26 application = service.Application("copy_receiver")
27 internet.TCPServer(8800, pb.PBServerFactory(Receiver())).setServiceParent(
28     service.IServiceCollection(application))