Roger Meier | cd9bc46 | 2011-01-03 20:19:07 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 | |
| 22 | from twisted.application import internet, service |
| 23 | from thrift.transport import TTwisted |
| 24 | |
Roger Meier | 1d66d06 | 2012-10-26 21:46:18 +0000 | [diff] [blame] | 25 | import sys, glob |
| 26 | sys.path.append('gen-py.twisted') |
| 27 | sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0]) |
Roger Meier | cd9bc46 | 2011-01-03 20:19:07 +0000 | [diff] [blame] | 28 | from tutorial import Calculator |
| 29 | from tutorial.ttypes import * |
| 30 | from PythonServer import CalculatorHandler |
| 31 | |
| 32 | def make_application(): |
| 33 | application = service.Application('CalcServer') |
| 34 | |
| 35 | handler = CalculatorHandler() |
| 36 | processor = Calculator.Processor(handler) |
| 37 | |
| 38 | serverFactory = TTwisted.ThriftServerFactory(processor, |
| 39 | TBinaryProtocol.TBinaryProtocolFactory()) |
| 40 | |
| 41 | calcService = internet.TCPServer(9090, serverFactory) |
| 42 | |
| 43 | multiService = service.MultiService() |
| 44 | calcService.setServiceParent(multiService) |
| 45 | multiService.setServiceParent(application) |
| 46 | |
| 47 | return application |
| 48 | |
| 49 | application = make_application() |