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): |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 9 | def __init__(self): |
| 10 | self.value = 0 |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 11 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 12 | def incr(self, amount): |
| 13 | self.value += amount |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 14 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 15 | def get(self): |
| 16 | return self.value |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | def main(): |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 20 | handler = StorageHandler() |
| 21 | processor = storage.Storage.Processor(handler) |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 22 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 23 | ctx = zmq.Context() |
| 24 | reqrep_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9090", zmq.REP) |
Stefan Bolus | e59b73d | 2018-05-14 14:48:09 +0200 | [diff] [blame^] | 25 | oneway_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9091", zmq.PULL) |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 26 | multiserver = TZmqServer.TZmqMultiServer() |
| 27 | multiserver.servers.append(reqrep_server) |
| 28 | multiserver.servers.append(oneway_server) |
| 29 | multiserver.serveForever() |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | if __name__ == "__main__": |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 33 | main() |