/
rpc_server.py
43 lines (31 loc) · 1.03 KB
/
rpc_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
'''
Created on 2011-11-28
@author: lixiaojun
'''
from jobs.task import CyeTask
from libs import jsonrpc
from libs.cyetools import logger
from libs.threadpool import ThreadPool, TaskQueue, ThreadPoolManager, \
LoadBalancingThread
def echo(self):
return 'Hello world!'
def join(sid):
if sid is None:
sid = 'cye'
queue = TaskQueue.getInstance()
queue.addTask(CyeTask(sid))
return "rpc say: success! "
if __name__ == '__main__':
thread_pool = ThreadPool.getInstance()
task_queue = TaskQueue.getInstance()
thread_pool.initPool(10, 25)
task_queue.initQueue()
pm = ThreadPoolManager(thread_pool, task_queue)
pm.proceed()
lb = LoadBalancingThread(15, thread_pool)
lb.proceed()
server = jsonrpc.Server(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", 31415), timeout=30.0, logfunc=jsonrpc.log_file("logs/cyepusher_rpc.log")))
server.register_function(echo)
server.register_function(join)
server.serve()