blob: 1d0b6c4b1e6ada5accd4c1b53fdf1f187c3f9efc [file] [log] [blame]
Roger Meiercd9bc462011-01-03 20:19:07 +00001#!/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
22from twisted.application import internet, service
23from thrift.transport import TTwisted
24
Roger Meier1d66d062012-10-26 21:46:18 +000025import sys, glob
26sys.path.append('gen-py.twisted')
27sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
Roger Meiercd9bc462011-01-03 20:19:07 +000028from tutorial import Calculator
29from tutorial.ttypes import *
30from PythonServer import CalculatorHandler
31
32def 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
49application = make_application()