Commit b2ce833d authored by Julien Muchembled's avatar Julien Muchembled

client: small optimizations

parent 990d6337
......@@ -25,14 +25,8 @@ class BaseHandler(EventHandler):
self.dispatcher = app.dispatcher
def dispatch(self, conn, packet, kw={}):
# Before calling superclass's dispatch method, lock the connection.
# This covers the case where handler sends a response to received
# packet.
conn.lock()
try:
assert conn._lock._is_owned()
super(BaseHandler, self).dispatch(conn, packet, kw)
finally:
conn.release()
def packetReceived(self, conn, packet, kw={}):
"""Redirect all received packet to dispatcher thread."""
......
......@@ -133,7 +133,6 @@ class PrimaryNotificationsHandler(BaseHandler):
if node and node.isConnected():
node.getConnection().close()
class PrimaryAnswersHandler(AnswerBaseHandler):
""" Handle that process expected packets from the primary master """
......@@ -141,7 +140,7 @@ class PrimaryAnswersHandler(AnswerBaseHandler):
self.app.setHandlerData(ttid)
def answerNewOIDs(self, conn, oid_list):
self.app.new_oid_list = list(oid_list)
self.app.new_oid_list = oid_list
def answerTransactionFinished(self, conn, _, tid):
self.app.setHandlerData(tid)
......
......@@ -728,36 +728,21 @@ class ServerConnection(Connection):
class MTClientConnection(ClientConnection):
"""A Multithread-safe version of ClientConnection."""
def __metaclass__(name, base, d):
for k in ('analyse', 'answer', 'checkTimeout',
'process', 'readable', 'writable'):
d[k] = lockCheckWrapper(getattr(base[0], k).im_func)
return type(name, base, d)
def __init__(self, *args, **kwargs):
# _lock is only here for lock debugging purposes. Do not use.
self._lock = lock = RLock()
self.acquire = lock.acquire
self.release = lock.release
self.lock = lock.acquire
self.unlock = lock.release
self.dispatcher = kwargs.pop('dispatcher')
self.dispatcher.needPollThread()
self.lock()
try:
with lock:
super(MTClientConnection, self).__init__(*args, **kwargs)
finally:
self.unlock()
def lock(self, blocking = 1):
return self.acquire(blocking = blocking)
def unlock(self):
self.release()
@lockCheckWrapper
def writable(self, *args, **kw):
return super(MTClientConnection, self).writable(*args, **kw)
@lockCheckWrapper
def readable(self, *args, **kw):
return super(MTClientConnection, self).readable(*args, **kw)
@lockCheckWrapper
def analyse(self, *args, **kw):
return super(MTClientConnection, self).analyse(*args, **kw)
def notify(self, *args, **kw):
self.lock()
......@@ -793,22 +778,9 @@ class MTClientConnection(ClientConnection):
finally:
self.unlock()
@lockCheckWrapper
def answer(self, *args, **kw):
return super(MTClientConnection, self).answer(*args, **kw)
@lockCheckWrapper
def checkTimeout(self, *args, **kw):
return super(MTClientConnection, self).checkTimeout(*args, **kw)
def close(self):
self.lock()
try:
super(MTClientConnection, self).close()
finally:
self.release()
@lockCheckWrapper
def process(self, *args, **kw):
return super(MTClientConnection, self).process(*args, **kw)
self.unlock()
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