blob: 299b84c523a2425583e31ef1ca3d4c61deda6997 [file] [log] [blame]
David Reiss9f3296b2010-08-31 16:58:41 +00001#!/usr/bin/env python
Jens Geyer72a714e2025-08-26 22:12:07 +02002
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 Reiss9f3296b2010-08-31 16:58:41 +000022import zmq
23import TZmqServer
24import storage.ttypes
25import storage.Storage
26
27
28class StorageHandler(storage.Storage.Iface):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090029 def __init__(self):
30 self.value = 0
David Reiss9f3296b2010-08-31 16:58:41 +000031
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090032 def incr(self, amount):
33 self.value += amount
David Reiss9f3296b2010-08-31 16:58:41 +000034
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090035 def get(self):
36 return self.value
David Reiss9f3296b2010-08-31 16:58:41 +000037
38
39def main():
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090040 handler = StorageHandler()
41 processor = storage.Storage.Processor(handler)
David Reiss9f3296b2010-08-31 16:58:41 +000042
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090043 ctx = zmq.Context()
44 reqrep_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9090", zmq.REP)
Stefan Boluse59b73d2018-05-14 14:48:09 +020045 oneway_server = TZmqServer.TZmqServer(processor, ctx, "tcp://0.0.0.0:9091", zmq.PULL)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090046 multiserver = TZmqServer.TZmqMultiServer()
47 multiserver.servers.append(reqrep_server)
48 multiserver.servers.append(oneway_server)
49 multiserver.serveForever()
David Reiss9f3296b2010-08-31 16:58:41 +000050
51
52if __name__ == "__main__":
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090053 main()