]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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 | ||
25 | import glob | |
26 | import sys | |
27 | sys.path.append('gen-py.twisted') | |
28 | sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0]) | |
29 | from tutorial import Calculator | |
30 | from PythonServer import CalculatorHandler | |
31 | from thrift.protocol import TBinaryProtocol | |
32 | ||
33 | ||
34 | def make_application(): | |
35 | application = service.Application('CalcServer') | |
36 | ||
37 | handler = CalculatorHandler() | |
38 | processor = Calculator.Processor(handler) | |
39 | ||
40 | serverFactory = TTwisted.ThriftServerFactory( | |
41 | processor, | |
42 | TBinaryProtocol.TBinaryProtocolFactory()) | |
43 | ||
44 | calcService = internet.TCPServer(9090, serverFactory) | |
45 | ||
46 | multiService = service.MultiService() | |
47 | calcService.setServiceParent(multiService) | |
48 | multiService.setServiceParent(application) | |
49 | ||
50 | return application | |
51 | ||
52 | if __name__ == '__main__': | |
53 | application = make_application() |