Commit 215250bb authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove 'connector_handler' parameter/attribute from Connection.

Merge both into 'connector' only to simplify API.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1884 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 7d0a1e25
......@@ -84,8 +84,8 @@ class Application(object):
# Make a listening port.
handler = AdminEventHandler(self)
ListeningConnection(self.em, handler, addr = self.server,
connector_handler = self.connector_handler)
ListeningConnection(self.em, handler, addr=self.server,
connector=self.connector_handler())
# Connect to a primary master node, verify data, and
# start the operation. This cycle will be executed permentnly,
......
......@@ -146,7 +146,7 @@ class BootstrapManager(EventHandler):
if conn is None:
# open the connection
addr = self.current.getAddress()
conn = ClientConnection(em, self, addr, connector_handler)
conn = ClientConnection(em, self, addr, connector_handler())
# still processing
em.poll(1)
node = nm.getByUUID(conn.getUUID())
......
......@@ -303,7 +303,7 @@ class Application(object):
# Connect to master
conn = MTClientConnection(self.em, self.notifications_handler,
addr=self.trying_master_node.getAddress(),
connector_handler=self.connector_handler,
connector=self.connector_handler(),
dispatcher=self.dispatcher)
# Query for primary master node
conn.lock()
......
......@@ -49,9 +49,9 @@ class ConnectionPool(object):
logging.debug('trying to connect to %s - %s', node, node.getState())
app.setNodeReady()
conn = MTClientConnection(app.em, app.storage_event_handler, addr,
connector_handler=app.connector_handler,
dispatcher=app.dispatcher)
connector=app.connector_handler(), dispatcher=app.dispatcher)
conn.lock()
try:
if conn.getConnector() is None:
# This happens, if a connection could not be established.
......
......@@ -123,17 +123,13 @@ class HandlerSwitcher(object):
class BaseConnection(object):
"""A base connection."""
def __init__(self, event_manager, handler, connector = None,
addr = None, connector_handler = None):
def __init__(self, event_manager, handler, connector, addr=None):
assert connector is not None, "Need a low-level connector"
self.em = event_manager
self.connector = connector
self.addr = addr
self._handlers = HandlerSwitcher(self, handler)
if connector is not None:
self.connector_handler = connector.__class__
event_manager.register(self)
else:
self.connector_handler = connector_handler
event_manager.register(self)
def lock(self):
return 1
......@@ -144,13 +140,6 @@ class BaseConnection(object):
def getConnector(self):
return self.connector
def setConnector(self, connector):
if self.connector is not None:
raise RuntimeError, 'cannot overwrite a connector in a connection'
if connector is not None:
self.connector = connector
self.em.register(self)
def getAddress(self):
return self.addr
......@@ -162,8 +151,8 @@ class BaseConnection(object):
def close(self):
"""Close the connection."""
em = self.em
if self.connector is not None:
em = self.em
em.removeReader(self)
em.removeWriter(self)
em.unregister(self)
......@@ -212,14 +201,11 @@ attributeTracker.track(BaseConnection)
class ListeningConnection(BaseConnection):
"""A listen connection."""
def __init__(self, event_manager, handler, addr, connector_handler, **kw):
def __init__(self, event_manager, handler, addr, connector, **kw):
logging.debug('listening to %s:%d', *addr)
BaseConnection.__init__(self, event_manager, handler,
addr = addr,
connector_handler = connector_handler)
connector = connector_handler()
connector.makeListeningConnection(addr)
self.setConnector(connector)
addr=addr, connector=connector)
self.connector.makeListeningConnection(addr)
self.em.addReader(self)
def readable(self):
......@@ -228,7 +214,7 @@ class ListeningConnection(BaseConnection):
logging.debug('accepted a connection from %s:%d', *addr)
handler = self.getHandler()
new_conn = ServerConnection(self.getEventManager(), handler,
connector=new_s, addr=addr)
connector=new_s, addr=addr)
handler.connectionAccepted(new_conn)
except ConnectorTryAgainException:
pass
......@@ -243,9 +229,9 @@ class ListeningConnection(BaseConnection):
class Connection(BaseConnection):
"""A connection."""
def __init__(self, event_manager, handler,
connector = None, addr = None,
connector_handler = None):
def __init__(self, event_manager, handler, connector, addr=None):
BaseConnection.__init__(self, event_manager, handler,
connector=connector, addr=addr)
self.read_buf = []
self.write_buf = []
self.cur_id = 0
......@@ -255,11 +241,7 @@ class Connection(BaseConnection):
self.uuid = None
self._queue = []
self._on_close = None
BaseConnection.__init__(self, event_manager, handler,
connector = connector, addr = addr,
connector_handler = connector_handler)
if connector is not None:
event_manager.addReader(self)
event_manager.addReader(self)
def setOnClose(self, callback):
assert self._on_close is None
......@@ -522,22 +504,19 @@ class Connection(BaseConnection):
class ClientConnection(Connection):
"""A connection from this node to a remote node."""
def __init__(self, event_manager, handler, addr, connector_handler, **kw):
def __init__(self, event_manager, handler, addr, connector, **kw):
self.connecting = True
Connection.__init__(self, event_manager, handler, addr = addr,
connector_handler = connector_handler)
Connection.__init__(self, event_manager, handler, addr=addr,
connector=connector)
handler.connectionStarted(self)
try:
connector = connector_handler()
self.setConnector(connector)
try:
connector.makeClientConnection(addr)
self.connector.makeClientConnection(addr)
except ConnectorInProgressException:
event_manager.addWriter(self)
else:
self.connecting = False
self.getHandler().connectionCompleted(self)
event_manager.addReader(self)
except ConnectorConnectionRefusedException:
self._closure(was_connected=True)
except ConnectorException:
......
......@@ -96,7 +96,7 @@ class Application(object):
# Make a listening port.
self.listening_conn = ListeningConnection(self.em, None,
addr = self.server, connector_handler = self.connector_handler)
addr=self.server, connector=self.connector_handler())
# Start a normal operation.
while True:
......@@ -189,7 +189,7 @@ class Application(object):
self.em.getClientList()]
if addr not in current_connections:
ClientConnection(self.em, client_handler, addr=addr,
connector_handler=self.connector_handler)
connector=self.connector_handler())
self.em.poll(1)
if len(self.unconnected_master_node_set |
......@@ -414,7 +414,7 @@ class Application(object):
if not connected_to_master:
ClientConnection(self.em, primary_handler, addr=addr,
connector_handler=self.connector_handler)
connector=self.connector_handler())
# and another for the future incoming connections
handler = identification.IdentificationHandler(self)
......
......@@ -38,9 +38,8 @@ class NeoCTL(object):
def __getConnection(self):
if not self.connected:
self.connection = ClientConnection(
self.em, self.handler, addr=self.server,
connector_handler=self.connector_handler)
self.connection = ClientConnection(self.em, self.handler,
addr=self.server, connector=self.connector_handler())
while not self.connected and self.connection is not None:
self.em.poll(0)
if self.connection is None:
......
......@@ -133,7 +133,7 @@ class Application(object):
# Make a listening port
handler = identification.IdentificationHandler(self)
self.listening_conn = ListeningConnection(self.em, handler,
addr=self.server, connector_handler=self.connector_handler)
addr=self.server, connector=self.connector_handler())
# Connect to a primary master node, verify data, and
# start the operation. This cycle will be executed permentnly,
......
......@@ -174,7 +174,7 @@ class Replicator(object):
if self.current_connection is None:
handler = replication.ReplicationHandler(app)
self.current_connection = ClientConnection(app.em, handler,
addr = addr, connector_handler = app.connector_handler)
addr=addr, connector=app.connector_handler())
p = Packets.RequestIdentification(NodeTypes.STORAGE,
app.uuid, app.server, app.name)
self.current_connection.ask(p)
......
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