blob: d89b37ba207f41ee29bcda4a9358a3181867e8b6 [file] [log] [blame]
David Reiss9f3296b2010-08-31 16:58:41 +00001#!/usr/bin/env python
2import zmq
3import TZmqServer
4import storage.ttypes
5import storage.Storage
6
7
8class StorageHandler(storage.Storage.Iface):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +09009 def __init__(self):
10 self.value = 0
David Reiss9f3296b2010-08-31 16:58:41 +000011
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090012 def incr(self, amount):
13 self.value += amount
David Reiss9f3296b2010-08-31 16:58:41 +000014
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090015 def get(self):
16 return self.value
David Reiss9f3296b2010-08-31 16:58:41 +000017
18
19def main():
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090020 handler = StorageHandler()
21 processor = storage.Storage.Processor(handler)
David Reiss9f3296b2010-08-31 16:58:41 +000022
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090023 ctx = zmq.Context()
24 reqrep_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9090", zmq.REP)
Stefan Boluse59b73d2018-05-14 14:48:09 +020025 oneway_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9091", zmq.PULL)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090026 multiserver = TZmqServer.TZmqMultiServer()
27 multiserver.servers.append(reqrep_server)
28 multiserver.servers.append(oneway_server)
29 multiserver.serveForever()
David Reiss9f3296b2010-08-31 16:58:41 +000030
31
32if __name__ == "__main__":
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090033 main()