diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/js/imc.js (renamed from src/test/imc.js) | 0 | ||||
-rw-r--r-- | src/py/backend_server.py | 6 | ||||
-rw-r--r-- | src/py/center_server.py | 21 | ||||
-rw-r--r-- | src/py/imc/nonblock.py | 34 | ||||
-rw-r--r-- | src/test/wstest.js | 75 |
5 files changed, 78 insertions, 58 deletions
diff --git a/src/test/imc.js b/src/js/imc.js index 98f2bdb..98f2bdb 100644 --- a/src/test/imc.js +++ b/src/js/imc.js diff --git a/src/py/backend_server.py b/src/py/backend_server.py index f750a1e..0334417 100644 --- a/src/py/backend_server.py +++ b/src/py/backend_server.py @@ -90,6 +90,8 @@ class BackendWorker(tornado.tcpserver.TCPServer): def _conn_center(self): def __retry(): print('retry connect center') + + self.center_conn = None self._ioloop.add_timeout(datetime.timedelta(seconds = 5),self._conn_center) def __send_worker_info(): @@ -161,6 +163,10 @@ class BackendWorker(tornado.tcpserver.TCPServer): }),'utf-8')) netio.recv_pack(stream,___recv_cb) + if self.center_conn == None: + callback(None) + return + stat,ret = (yield imc_call(self._iden,'/center/' + self.center_conn.linkid + '/','lookup_linkid',linkid)) if stat == False or ret == None: diff --git a/src/py/center_server.py b/src/py/center_server.py index a5dac27..322f681 100644 --- a/src/py/center_server.py +++ b/src/py/center_server.py @@ -55,7 +55,7 @@ class CenterServer(tornado.tcpserver.TCPServer): self._linkid_usemap = {} self._worker_linkidmap = {} - self._client_linkidmap = {} + self._backend_clientmap = {} self._backend_workerlist = [] self.linkclass = 'center' @@ -84,10 +84,12 @@ class CenterServer(tornado.tcpserver.TCPServer): def add_backend_worker(self,backend): self._worker_linkidmap[backend.linkid] = backend + self._backend_clientmap[backend.linkid] = {} self._backend_workerlist.append(backend) def del_backend_worker(self,backend): self._worker_linkidmap.pop(backend.linkid,None) + del self._backend_clientmap[backend.linkid] self._backend_workerlist.remove(backend) def dispatch_client(self): @@ -128,10 +130,10 @@ class CenterServer(tornado.tcpserver.TCPServer): @imc.nonblock.func def _add_client(self,iden,param): - backend_linkid = param['backend_linkid'] + backend_linkid = iden['linkid'] client_linkid = param['client_linkid'] - self._client_linkidmap[client_linkid] = True + self._backend_clientmap[backend_linkid][client_linkid] = True conn = Proxy.instance.get_conn(backend_linkid) Proxy.instance.link_conn(client_linkid,conn) @@ -141,12 +143,15 @@ class CenterServer(tornado.tcpserver.TCPServer): @imc.nonblock.func def _del_client(self,iden,param): + backend_linkid = iden['linkid'] client_linkid = param - del self._client_linkidmap[client_linkid] + del self._backend_clientmap[backend_linkid][client_linkid] conn = Proxy.instance.get_conn(client_linkid) Proxy.instance.unlink_conn(client_linkid) + + @imc.nonblock.func def _test_dst(self,iden,param): #stat,ret = (yield imc_call( @@ -157,9 +162,11 @@ class CenterServer(tornado.tcpserver.TCPServer): #)) linkidlist = [] - linkids = self._client_linkidmap.keys() - for linkid in linkids: - linkidlist.append(linkid) + clientmaps = self._backend_clientmap.values() + for clientmap in clientmaps: + linkids = clientmap.keys() + for linkid in linkids: + linkidlist.append(linkid) return linkidlist diff --git a/src/py/imc/nonblock.py b/src/py/imc/nonblock.py index 02f291d..267bbaa 100644 --- a/src/py/imc/nonblock.py +++ b/src/py/imc/nonblock.py @@ -18,20 +18,27 @@ def func(f): global gen_current_id global gen_waitmap - gen = f(*args,**kwargs) - if isinstance(gen,types.GeneratorType): - gen_current_id = str(id(gen)) - gen_waitmap[gen_current_id] = gen + try: + gen = f(*args,**kwargs) + if isinstance(gen,types.GeneratorType): + gen_current_id = str(id(gen)) + gen_waitmap[gen_current_id] = gen - try: - next(gen) + try: + next(gen) - return (False,gen_current_id) - except StopIteration as ret: - del gen_waitmap[gen_current_id] - return (True,ret) - else: - return (True,gen) + return (False,gen_current_id) + + except StopIteration as ret: + del gen_waitmap[gen_current_id] + return (True,ret) + + + else: + return (True,gen) + + except Exception: + return (True,'Einternal') return wrapper @@ -49,3 +56,6 @@ def retcall(genid,value): except StopIteration as err: del gen_waitmap[gen_current_id] return (True,err.value) + + except Exception: + return (True,'Einternal') diff --git a/src/test/wstest.js b/src/test/wstest.js index cc7806d..4ad0d83 100644 --- a/src/test/wstest.js +++ b/src/test/wstest.js @@ -4,31 +4,6 @@ var data = new ArrayBuffer(1024); var linkid = null; var iden = null; -var backend_conn = null; - -function test(){ - $.post('http://toj.tfcis.org:83/conn',{},function(res){ - var reto; - - if(res[0] != 'E'){ - reto = JSON.parse(res) - linkid = reto.client_linkid; - - console.log(linkid); - - new imc.Proxy(linkid,function(linkid,callback){ - callback(backend_conn); - }); - iden = {'linkclass':'client','linkid':linkid}; - - imc_register_call('','test_call',test_call); - - conn_backend(reto.client_linkid,reto.backend_linkid,reto.ip,reto.port); - }else{ - - } - }); -} function test_call(param,callback){ callback('Hello Too'); @@ -59,26 +34,48 @@ var WebSocketConnection = function(linkid,ws){ ws.onclose = function(e){ console.log('close'); that.close(); - }; - - backend_conn = that; + conn_backend(); + }; };__extend__(WebSocketConnection,imc.Connection); function conn_backend(client_linkid,backend_linkid,ip,port){ - var ws; - - ws = new WebSocket('ws://' + ip + ':' + port + '/conn'); - ws.onopen = function(){ - var i; + $.post('http://toj.tfcis.org:83/conn',{},function(res){ + var reto; + var ws; + + if(res[0] != 'E'){ + reto = JSON.parse(res) + linkid = reto.client_linkid; - console.log('open'); + ws = new WebSocket('ws://' + reto.ip + ':' + reto.port + '/conn'); + ws.onopen = function(){ + var i; + var conn; - ws.send(JSON.stringify({ - 'client_linkid':client_linkid - })); - imc.Proxy.instance.add_conn(new WebSocketConnection(backend_linkid,ws)); - }; + console.log('open'); + + ws.send(JSON.stringify({ + 'client_linkid':reto.client_linkid + })); + + conn = new WebSocketConnection(reto.backend_linkid,ws); + + new imc.Proxy(linkid,function(linkid,callback){ + callback(conn); + }); + imc.Proxy.instance.add_conn(conn); + + iden = {'linkclass':'client','linkid':linkid}; + + imc_register_call('','test_call',test_call); + }; + }else{ + setTimeout(conn_backend,5000); + } + }); + + } function perf(){ |