Commit 468227b4 authored by Vincent Pelletier's avatar Vincent Pelletier

Use a registry mechanism for Connector instances.

Allow providing non-basestring values as connector parameter, which are then passedthrough as replacements for Connector classes. This is usefull to modify Connector class behaviour in tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@281 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent c2878e99
......@@ -35,7 +35,7 @@ from neo.client.handler import ClientEventHandler
from neo.client.exception import NEOStorageError, NEOStorageConflictError, \
NEOStorageNotFoundError
from neo.util import makeChecksum, dump
from neo import connector as Connector
from neo.connector import getConnectorHandler
from ZODB.POSException import UndoError, StorageTransactionError, ConflictError
from ZODB.utils import p64, u64, oid_repr
......@@ -180,7 +180,7 @@ class Application(object):
# Internal Attributes common to all thread
self.name = name
self.em = em
self.connector_handler = getattr(Connector, connector)
self.connector_handler = getConnectorHandler(connector)
self.dispatcher = dispatcher
self.nm = NodeManager()
self.cp = ConnectionPool(self)
......
......@@ -18,7 +18,23 @@
import socket
import errno
import logging
from neo.master.tests.connector import *
# Global connector registry.
# Fill by calling registerConnectorHandler.
# Read by calling getConnectorHandler.
connector_registry = {}
def registerConnectorHandler(connector_handler):
connector_registry[connector_handler.__name__] = connector_handler
def getConnectorHandler(connector):
if isinstance(connector, basestring):
connector_handler = connector_registry.get(connector)
else:
# Allow to directly provide a handler class without requiring to register
# it first.
connector_handler = connector
return connector_handler
class SocketConnector:
""" This class is a wrapper for a socket """
......@@ -99,6 +115,7 @@ class SocketConnector:
logging.error('send: %s', m[1])
raise
registerConnectorHandler(SocketConnector)
class ConnectorTryAgainException(Exception): pass
class ConnectorInProgressException(Exception): pass
......
......@@ -36,7 +36,7 @@ from neo.master.service import ServiceEventHandler
from neo.master.secondary import SecondaryEventHandler
from neo.pt import PartitionTable
from neo.util import dump
from neo import connector
from neo.connector import getConnectorHandler
class Application(object):
"""The master node application."""
......@@ -47,8 +47,7 @@ class Application(object):
self.num_replicas = config.getReplicas()
self.num_partitions = config.getPartitions()
self.name = config.getName()
connector_handler = config.getConnector()
self.connector_handler = getattr(connector, connector_handler)
self.connector_handler = getConnectorHandler(config.getConnector())
logging.debug('the number of replicas is %d, the number of partitions is %d, the name is %s',
self.num_replicas, self.num_partitions, self.name)
......
......@@ -33,7 +33,7 @@ from neo.storage.bootstrap import BootstrapEventHandler
from neo.storage.verification import VerificationEventHandler
from neo.storage.operation import OperationEventHandler
from neo.storage.replicator import Replicator
from neo import connector
from neo.connector import getConnectorHandler
class Application(object):
"""The storage node application."""
......@@ -45,8 +45,7 @@ class Application(object):
self.num_replicas = None
self.name = config.getName()
logging.debug('the name is %s', self.name)
connector_handler = config.getConnector()
self.connector_handler = getattr(connector, connector_handler)
self.connector_handler = getConnectorHandler(config.getConnector())
self.server = config.getServer()
logging.debug('IP address is %s, port is %d', *(self.server))
......
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