David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
Jens Geyer | 72a714e | 2025-08-26 22:12:07 +0200 | [diff] [blame^] | 2 | |
| 3 | # |
| 4 | # Licensed to the Apache Software Foundation (ASF) under one |
| 5 | # or more contributor license agreements. See the NOTICE file |
| 6 | # distributed with this work for additional information |
| 7 | # regarding copyright ownership. The ASF licenses this file |
| 8 | # to you under the Apache License, Version 2.0 (the |
| 9 | # "License"); you may not use this file except in compliance |
| 10 | # with the License. You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, |
| 15 | # software distributed under the License is distributed on an |
| 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | # KIND, either express or implied. See the License for the |
| 18 | # specific language governing permissions and limitations |
| 19 | # under the License. |
| 20 | # |
| 21 | |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 22 | import zmq |
| 23 | import TZmqServer |
| 24 | import storage.ttypes |
| 25 | import storage.Storage |
| 26 | |
| 27 | |
| 28 | class StorageHandler(storage.Storage.Iface): |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 29 | def __init__(self): |
| 30 | self.value = 0 |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 31 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 32 | def incr(self, amount): |
| 33 | self.value += amount |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 34 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 35 | def get(self): |
| 36 | return self.value |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | def main(): |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 40 | handler = StorageHandler() |
| 41 | processor = storage.Storage.Processor(handler) |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 42 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 43 | ctx = zmq.Context() |
| 44 | 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] | 45 | 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] | 46 | multiserver = TZmqServer.TZmqMultiServer() |
| 47 | multiserver.servers.append(reqrep_server) |
| 48 | multiserver.servers.append(oneway_server) |
| 49 | multiserver.serveForever() |
David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | if __name__ == "__main__": |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 53 | main() |