blob: c7804d317a1ff54de16dd50ad3d41913086edbb2 [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)
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()
David Reiss9f3296b2010-08-31 16:58:41 +000030
31
32if __name__ == "__main__":
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090033 main()