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