Commit 4865e8f6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Revert r1812 & r1814 (node manager as a singleton).

Singeltons can not be used in NEO because client side process may deals with
multiple NEO cluster. Add a callback on connection when linked with a node to
update node's connection property at connection closure.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1826 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2ed974e6
......@@ -52,13 +52,12 @@ class Application(object):
def __init__(self, config):
NodeManager.init()
# always use default connector for now
self.connector_handler = getConnectorHandler()
# Internal attributes.
self.em = EventManager()
self.nm = NodeManager
self.nm = NodeManager()
self.name = config.getCluster()
self.server = config.getBind()
......
......@@ -100,8 +100,6 @@ class Application(object):
"""The client node application."""
def __init__(self, master_nodes, name, connector=None, **kw):
NodeManager.init()
# Start polling thread
self.em = EventManager()
self.poll_thread = ThreadedPoll(self.em)
......@@ -110,7 +108,7 @@ class Application(object):
self.name = name
self.connector_handler = getConnectorHandler(connector)
self.dispatcher = Dispatcher()
self.nm = NodeManager
self.nm = NodeManager()
self.cp = ConnectionPool(self)
self.pt = None
self.master_conn = None
......
......@@ -202,6 +202,7 @@ class Connection(BaseConnection):
self._queue = []
self._expected = deque()
self._next_handler = None
self._on_close = None
BaseConnection.__init__(self, event_manager, handler,
connector = connector, addr = addr,
connector_handler = connector_handler)
......@@ -219,6 +220,10 @@ class Connection(BaseConnection):
else:
self.handler = handler
def setOnClose(self, callback):
assert self._on_close is None
self._on_close = callback
def isAborted(self):
return self.aborted
......@@ -245,10 +250,9 @@ class Connection(BaseConnection):
BaseConnection.close(self)
for event in self.event_dict.itervalues():
self.em.removeIdleEvent(event)
from neo.node import NodeManager
node = NodeManager.getByUUID(self.getUUID())
if node is not None:
node.setConnection(None)
if self._on_close is not None:
self._on_close()
self._on_close = None
self.event_dict.clear()
self.write_buf = ""
self.read_buf = ""
......
......@@ -42,13 +42,12 @@ class Application(object):
def __init__(self, config):
NodeManager.init()
# always use default connector for now
self.connector_handler = getConnectorHandler()
# Internal attributes.
self.em = EventManager()
self.nm = NodeManager
self.nm = NodeManager()
self.tm = TransactionManager()
self.name = config.getCluster()
......
......@@ -36,7 +36,6 @@ class StorageServiceHandler(BaseServiceHandler):
def nodeLost(self, conn, node):
logging.info('storage node lost')
assert not node.isRunning(), node.getState()
node.setConnection(None)
if not self.app.pt.operational():
raise OperationFailure, 'cannot continue operation'
......
......@@ -106,7 +106,6 @@ class RecoveryManager(MasterHandler):
assert node is not None
if node.getState() == new_state:
return
node.setConnection(None)
node.setState(new_state)
def connectionCompleted(self, conn):
......
......@@ -249,7 +249,6 @@ class VerificationManager(BaseServiceHandler):
pass
def nodeLost(self, conn, node):
node.setConnection(None)
if not self.app.pt.operational():
raise VerificationFailure, 'cannot continue verification'
......@@ -77,9 +77,15 @@ class Node(object):
def getUUID(self):
return self._uuid
def onConnectionClosed(self):
assert self._connection is not None
self._connection = None
def setConnection(self, connection):
assert self._connection is None or connection is None
assert connection is not None
assert self._connection is None
self._connection = connection
connection.setOnClose(self.onConnectionClosed)
def getConnection(self):
assert self._connection is not None
......@@ -429,5 +435,3 @@ class NodeManager(object):
logging.debug(' * %32s | %8s | %22s | %s' % (
uuid, node.getType(), address, node.getState()))
# pseudo singleton
NodeManager = NodeManager()
......@@ -38,8 +38,6 @@ class Application(object):
"""The storage node application."""
def __init__(self, config):
NodeManager.init()
# always use default connector for now
self.connector_handler = getConnectorHandler()
......@@ -48,7 +46,7 @@ class Application(object):
# Internal attributes.
self.em = EventManager()
self.nm = NodeManager
self.nm = NodeManager()
self.tm = TransactionManager(self)
self.dm = buildDatabaseManager(config.getAdapter(), config.getDatabase())
......
......@@ -125,7 +125,7 @@ class NodesTests(NeoTestBase):
class NodeManagerTests(NeoTestBase):
def setUp(self):
self.manager = nm = NodeManager.__class__()
self.manager = nm = NodeManager()
self.storage = StorageNode(nm, ('127.0.0.1', 1000), self.getNewUUID())
self.master = MasterNode(nm, ('127.0.0.1', 2000), self.getNewUUID())
self.client = ClientNode(nm, None, self.getNewUUID())
......
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