Commit d0775e40 authored by Aurel's avatar Aurel

remove busy loop


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@176 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent d7a5b14b
...@@ -49,74 +49,67 @@ class Dispatcher(Thread): ...@@ -49,74 +49,67 @@ class Dispatcher(Thread):
if app.pt is not None: if app.pt is not None:
app.pt.clear() app.pt.clear()
master_index = 0 master_index = 0
t = 0
conn = None conn = None
# Make application execute remaining message if any # Make application execute remaining message if any
app._waitMessage() app._waitMessage()
# Wait a bit before trying to reconnect
t = time()
while time() < t + 1:
pass
handler = ClientEventHandler(app, app.dispatcher) handler = ClientEventHandler(app, app.dispatcher)
while 1: while 1:
if app.pt is not None and app.pt.operational(): if t + 1 < time():
# Connected to primary master node and got all informations if app.pt is not None and app.pt.operational():
break # Connected to primary master node and got all informations
app.node_not_ready = 0 break
if app.primary_master_node is None: app.node_not_ready = 0
# Try with master node defined in config if app.primary_master_node is None:
addr, port = app.master_node_list[master_index].split(':') # Try with master node defined in config
port = int(port) addr, port = app.master_node_list[master_index].split(':')
else: port = int(port)
addr, port = app.primary_master_node.getServer() else:
# Request Node Identification addr, port = app.primary_master_node.getServer()
conn = MTClientConnection(app.em, handler, (addr, port)) # Request Node Identification
if app.nm.getNodeByServer((addr, port)) is None: conn = MTClientConnection(app.em, handler, (addr, port))
n = MasterNode(server = (addr, port)) if app.nm.getNodeByServer((addr, port)) is None:
app.nm.add(n) n = MasterNode(server = (addr, port))
app.nm.add(n)
conn.lock() conn.lock()
try: try:
msg_id = conn.getNextId() msg_id = conn.getNextId()
p = Packet() p = Packet()
p.requestNodeIdentification(msg_id, CLIENT_NODE_TYPE, app.uuid, p.requestNodeIdentification(msg_id, CLIENT_NODE_TYPE, app.uuid,
'0.0.0.0', 0, app.name) '0.0.0.0', 0, app.name)
# Send message # Send message
conn.addPacket(p) conn.addPacket(p)
conn.expectMessage(msg_id) conn.expectMessage(msg_id)
self.register(conn, msg_id, app.getQueue()) self.register(conn, msg_id, app.getQueue())
finally: finally:
conn.unlock() conn.unlock()
# Wait for answer # Wait for answer
while 1: while 1:
try: try:
self.em.poll(1) self.em.poll(1)
except TypeError: except TypeError:
t = time()
while time() < t + 1:
pass
break
app._waitMessage()
# Now check result
if app.primary_master_node is not None:
if app.primary_master_node == -1:
# Connection failed, try with another master node
app.primary_master_node = None
master_index += 1
break
elif app.primary_master_node.getServer() != (addr, port):
# Master node changed, connect to new one
break
elif app.node_not_ready:
# Wait a bit and reask again
t = time()
while time() < t + 1:
pass
break
elif app.pt is not None and app.pt.operational():
# Connected to primary master node
break break
app._waitMessage()
# Now check result
if app.primary_master_node is not None:
if app.primary_master_node == -1:
# Connection failed, try with another master node
app.primary_master_node = None
master_index += 1
break
elif app.primary_master_node.getServer() != (addr, port):
# Master node changed, connect to new one
break
elif app.node_not_ready:
# Wait a bit and reask again
break
elif app.pt is not None and app.pt.operational():
# Connected to primary master node
break
t = time()
logging.info("connected to primary master node %s:%d" %app.primary_master_node.getServer()) logging.info("connected to primary master node %s:%d" %app.primary_master_node.getServer())
app.master_conn = conn app.master_conn = conn
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment