David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import zmq |
| 3 | import TZmqServer |
| 4 | import storage.ttypes |
| 5 | import storage.Storage |
| 6 | |
| 7 | |
| 8 | class StorageHandler(storage.Storage.Iface): |
| 9 | def __init__(self): |
| 10 | self.value = 0 |
| 11 | |
| 12 | def incr(self, amount): |
| 13 | self.value += amount |
| 14 | |
| 15 | def get(self): |
| 16 | return self.value |
| 17 | |
| 18 | |
| 19 | def main(): |
| 20 | handler = StorageHandler() |
| 21 | processor = storage.Storage.Processor(handler) |
| 22 | |
| 23 | ctx = zmq.Context() |
| 24 | reqrep_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9090", zmq.REP) |
| 25 | oneway_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9091", zmq.UPSTREAM) |
| 26 | multiserver = TZmqServer.TZmqMultiServer() |
| 27 | multiserver.servers.append(reqrep_server) |
| 28 | multiserver.servers.append(oneway_server) |
| 29 | multiserver.serveForever() |
| 30 | |
| 31 | |
| 32 | if __name__ == "__main__": |
| 33 | main() |