[Neo-report] r1884 gregory - in /trunk/neo: ./ admin/ client/ master/ neoctl/ storage/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Mar 1 18:10:36 CET 2010
Author: gregory
Date: Mon Mar 1 18:10:35 2010
New Revision: 1884
Log:
Remove 'connector_handler' parameter/attribute from Connection.
Merge both into 'connector' only to simplify API.
Modified:
trunk/neo/admin/app.py
trunk/neo/bootstrap.py
trunk/neo/client/app.py
trunk/neo/client/pool.py
trunk/neo/connection.py
trunk/neo/master/app.py
trunk/neo/neoctl/neoctl.py
trunk/neo/storage/app.py
trunk/neo/storage/replicator.py
Modified: trunk/neo/admin/app.py
==============================================================================
--- trunk/neo/admin/app.py [iso-8859-1] (original)
+++ trunk/neo/admin/app.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -84,8 +84,8 @@
# 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,
Modified: trunk/neo/bootstrap.py
==============================================================================
--- trunk/neo/bootstrap.py [iso-8859-1] (original)
+++ trunk/neo/bootstrap.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -146,7 +146,7 @@
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())
Modified: trunk/neo/client/app.py
==============================================================================
--- trunk/neo/client/app.py [iso-8859-1] (original)
+++ trunk/neo/client/app.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -303,7 +303,7 @@
# 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()
Modified: trunk/neo/client/pool.py
==============================================================================
--- trunk/neo/client/pool.py [iso-8859-1] (original)
+++ trunk/neo/client/pool.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -49,9 +49,9 @@
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.
Modified: trunk/neo/connection.py
==============================================================================
--- trunk/neo/connection.py [iso-8859-1] (original)
+++ trunk/neo/connection.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -123,17 +123,13 @@
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 @@
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 @@
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 @@
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 @@
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 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 @@
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 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:
Modified: trunk/neo/master/app.py
==============================================================================
--- trunk/neo/master/app.py [iso-8859-1] (original)
+++ trunk/neo/master/app.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -96,7 +96,7 @@
# 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 @@
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 @@
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)
Modified: trunk/neo/neoctl/neoctl.py
==============================================================================
--- trunk/neo/neoctl/neoctl.py [iso-8859-1] (original)
+++ trunk/neo/neoctl/neoctl.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -38,9 +38,8 @@
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:
Modified: trunk/neo/storage/app.py
==============================================================================
--- trunk/neo/storage/app.py [iso-8859-1] (original)
+++ trunk/neo/storage/app.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -133,7 +133,7 @@
# 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,
Modified: trunk/neo/storage/replicator.py
==============================================================================
--- trunk/neo/storage/replicator.py [iso-8859-1] (original)
+++ trunk/neo/storage/replicator.py [iso-8859-1] Mon Mar 1 18:10:35 2010
@@ -174,7 +174,7 @@
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)
More information about the Neo-report
mailing list