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 ...@@ -35,7 +35,7 @@ from neo.client.handler import ClientEventHandler
from neo.client.exception import NEOStorageError, NEOStorageConflictError, \ from neo.client.exception import NEOStorageError, NEOStorageConflictError, \
NEOStorageNotFoundError NEOStorageNotFoundError
from neo.util import makeChecksum, dump 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.POSException import UndoError, StorageTransactionError, ConflictError
from ZODB.utils import p64, u64, oid_repr from ZODB.utils import p64, u64, oid_repr
...@@ -180,7 +180,7 @@ class Application(object): ...@@ -180,7 +180,7 @@ class Application(object):
# Internal Attributes common to all thread # Internal Attributes common to all thread
self.name = name self.name = name
self.em = em self.em = em
self.connector_handler = getattr(Connector, connector) self.connector_handler = getConnectorHandler(connector)
self.dispatcher = dispatcher self.dispatcher = dispatcher
self.nm = NodeManager() self.nm = NodeManager()
self.cp = ConnectionPool(self) self.cp = ConnectionPool(self)
......
...@@ -18,7 +18,23 @@ ...@@ -18,7 +18,23 @@
import socket import socket
import errno import errno
import logging 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: class SocketConnector:
""" This class is a wrapper for a socket """ """ This class is a wrapper for a socket """
...@@ -99,6 +115,7 @@ class SocketConnector: ...@@ -99,6 +115,7 @@ class SocketConnector:
logging.error('send: %s', m[1]) logging.error('send: %s', m[1])
raise raise
registerConnectorHandler(SocketConnector)
class ConnectorTryAgainException(Exception): pass class ConnectorTryAgainException(Exception): pass
class ConnectorInProgressException(Exception): pass class ConnectorInProgressException(Exception): pass
......
...@@ -36,7 +36,7 @@ from neo.master.service import ServiceEventHandler ...@@ -36,7 +36,7 @@ from neo.master.service import ServiceEventHandler
from neo.master.secondary import SecondaryEventHandler from neo.master.secondary import SecondaryEventHandler
from neo.pt import PartitionTable from neo.pt import PartitionTable
from neo.util import dump from neo.util import dump
from neo import connector from neo.connector import getConnectorHandler
class Application(object): class Application(object):
"""The master node application.""" """The master node application."""
...@@ -47,8 +47,7 @@ class Application(object): ...@@ -47,8 +47,7 @@ class Application(object):
self.num_replicas = config.getReplicas() self.num_replicas = config.getReplicas()
self.num_partitions = config.getPartitions() self.num_partitions = config.getPartitions()
self.name = config.getName() self.name = config.getName()
connector_handler = config.getConnector() self.connector_handler = getConnectorHandler(config.getConnector())
self.connector_handler = getattr(connector, connector_handler)
logging.debug('the number of replicas is %d, the number of partitions is %d, the name is %s', 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) self.num_replicas, self.num_partitions, self.name)
......
...@@ -33,7 +33,7 @@ from neo.storage.bootstrap import BootstrapEventHandler ...@@ -33,7 +33,7 @@ from neo.storage.bootstrap import BootstrapEventHandler
from neo.storage.verification import VerificationEventHandler from neo.storage.verification import VerificationEventHandler
from neo.storage.operation import OperationEventHandler from neo.storage.operation import OperationEventHandler
from neo.storage.replicator import Replicator from neo.storage.replicator import Replicator
from neo import connector from neo.connector import getConnectorHandler
class Application(object): class Application(object):
"""The storage node application.""" """The storage node application."""
...@@ -45,8 +45,7 @@ class Application(object): ...@@ -45,8 +45,7 @@ class Application(object):
self.num_replicas = None self.num_replicas = None
self.name = config.getName() self.name = config.getName()
logging.debug('the name is %s', self.name) logging.debug('the name is %s', self.name)
connector_handler = config.getConnector() self.connector_handler = getConnectorHandler(config.getConnector())
self.connector_handler = getattr(connector, connector_handler)
self.server = config.getServer() self.server = config.getServer()
logging.debug('IP address is %s, port is %d', *(self.server)) 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