Commit 6b60a310 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Add __repr__ to Connection.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2056 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent fd11d103
......@@ -238,13 +238,12 @@ class BaseConnection(object):
if handlers.isPending():
msg_id = handlers.checkTimeout(t)
if msg_id is not None:
logging.info('timeout for %r with %s:%d', msg_id,
*self.getAddress())
logging.info('timeout for %r with %r', msg_id, self)
self.close()
self.getHandler().timeoutExpired(self)
elif self._timeout.hardExpired(t):
# critical time reach or pong not received, abort
logging.info('timeout with %s:%d', *(self.getAddress()))
logging.info('timeout with %r', self)
self.notify(Packets.Notify('Timeout'))
self.abort()
self.getHandler().timeoutExpired(self)
......@@ -281,6 +280,16 @@ class BaseConnection(object):
self.connector.close()
self.connector = None
def __repr__(self):
address = self.addr and '%s:%d' % self.addr or '?'
return '<%s(uuid=%s, address=%s, closed=%s) at %x>' % (
self.__class__.__name__,
dump(self.getUUID()),
address,
self.isClosed(),
id(self),
)
__del__ = close
def getHandler(self):
......@@ -395,8 +404,7 @@ class Connection(BaseConnection):
return next_id
def close(self):
logging.debug('closing a connector for %s (%s:%d)',
dump(self.uuid), *(self.addr))
logging.debug('closing a connector for %r', self)
BaseConnection.close(self)
if self._on_close is not None:
self._on_close()
......@@ -407,8 +415,7 @@ class Connection(BaseConnection):
def abort(self):
"""Abort dealing with this connection."""
logging.debug('aborting a connector for %s (%s:%d)',
dump(self.uuid), *(self.addr))
logging.debug('aborting a connector for %r', self)
self.aborted = True
def writable(self):
......
......@@ -58,7 +58,7 @@ class EventHandler(object):
except UnexpectedPacketError, e:
self.__unexpectedPacket(conn, packet, *e.args)
except PacketMalformedError:
logging.error('malformed packet from %s:%d', *(conn.getAddress()))
logging.error('malformed packet from %r', conn)
conn.notify(Packets.Notify('Malformed packet: %r' % (packet, )))
conn.abort()
self.peerBroken(conn)
......@@ -91,32 +91,32 @@ class EventHandler(object):
def connectionStarted(self, conn):
"""Called when a connection is started."""
logging.debug('connection started for %s:%d', *(conn.getAddress()))
logging.debug('connection started for %r', conn)
def connectionCompleted(self, conn):
"""Called when a connection is completed."""
logging.debug('connection completed for %s:%d', *(conn.getAddress()))
logging.debug('connection completed for %r', conn)
def connectionFailed(self, conn):
"""Called when a connection failed."""
logging.debug('connection failed for %s:%d', *(conn.getAddress()))
logging.debug('connection failed for %r', conn)
def connectionAccepted(self, conn):
"""Called when a connection is accepted."""
def timeoutExpired(self, conn):
"""Called when a timeout event occurs."""
logging.debug('timeout expired for %s:%d', *(conn.getAddress()))
logging.debug('timeout expired for %r', conn)
self.connectionLost(conn, NodeStates.TEMPORARILY_DOWN)
def connectionClosed(self, conn):
"""Called when a connection is closed by the peer."""
logging.debug('connection closed for %s:%d', *(conn.getAddress()))
logging.debug('connection closed for %r', conn)
self.connectionLost(conn, NodeStates.TEMPORARILY_DOWN)
def peerBroken(self, conn):
"""Called when a peer is broken."""
logging.error('%s:%d is broken', *(conn.getAddress()))
logging.error('%r is broken', conn)
self.connectionLost(conn, NodeStates.BROKEN)
def connectionLost(self, conn, new_state):
......@@ -128,7 +128,7 @@ class EventHandler(object):
# Packet handlers.
def notify(self, conn, message):
logging.info('notification from %s:%d: %s', *(conn.getAddress(), message))
logging.info('notification from %r: %s', conn, message)
def requestIdentification(self, conn, node_type,
uuid, address, name):
......
......@@ -350,8 +350,7 @@ class Application(object):
return
def playPrimaryRole(self):
logging.info('play the primary role with %s (%s:%d)',
dump(self.uuid), *(self.server))
logging.info('play the primary role with %r', self.listening_conn)
# i'm the primary, send the announcement
self._announcePrimary()
......@@ -388,8 +387,7 @@ class Application(object):
"""
I play a secondary role, thus only wait for a primary master to fail.
"""
logging.info('play the secondary role with %s (%s:%d)',
dump(self.uuid), *(self.server))
logging.info('play the secondary role with %r', self.listening_conn)
# Wait for an announcement. If this is too long, probably
# the primary master is down.
......
......@@ -90,7 +90,7 @@ class ClientElectionHandler(MasterHandler):
node = app.nm.getByAddress(conn.getAddress())
if node_type != NodeTypes.MASTER:
# The peer is not a master node!
logging.error('%s:%d is not a master node', *conn.getAddress())
logging.error('%r is not a master node', conn)
app.nm.remove(node)
app.negotiating_master_node_set.discard(node.getAddress())
conn.close()
......
......@@ -190,8 +190,7 @@ class VerificationManager(BaseServiceHandler):
def answerUnfinishedTransactions(self, conn, tid_list):
uuid = conn.getUUID()
logging.info('got unfinished transactions %s from %s:%d',
tid_list, *(conn.getAddress()))
logging.info('got unfinished transactions %s from %r', tid_list, conn)
if self._uuid_dict.get(uuid, True):
# No interest.
return
......
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