Ejemplo n.º 1
0
class TransactionManager(object):
    QUEUEDEBUG = False

    def __init__(self, monitor, debug=0):
        self.monitor = monitor
        self.debug = debug
        self.controllers = Dictionary()
        self.controller_lock = Lock()
        super(TransactionManager, self).__init__()

    def _get_controller(self, host, port, protocol):
        location = (host, port)
        self.controller_lock.acquire()
        try:
            if not self.controllers.has_key(location):
                self.controllers[location] = LocationController(
                    self.monitor, host, port, protocol, self.debug)
        finally:
            self.controller_lock.release()
        return self.controllers.get(location)

    def create_transaction(self, request, sid):
        controller = self._get_controller(request.get_host(),
                                          request.get_port(),
                                          request.get_type())

        if (controller.is_transaction_pending(sid)):
            if self.debug or self.QUEUEDEBUG:
                msglog.log(
                    'broadway', msglog.types.DB,
                    'Already Pending transaction, so not adding transaction. sid=%s'
                    % (sid))
            controller.recruit_and_send()
            return (None)

        transaction = Transaction(request, sid=sid)

        if self.debug or self.QUEUEDEBUG:
            before = repr(controller)
        controller.add_transaction(transaction)
        if self.debug or self.QUEUEDEBUG:
            after = repr(controller)
            message = 'Controller before and after adding transaction:\n'
            message += '    - Before: %s\n' % (before[1:-1])
            message += '    - After: %s\n' % (after[1:-1])
            msglog.log('broadway', msglog.types.DB, message)
        return transaction
Ejemplo n.º 2
0
class TransactionManager(object):
    QUEUEDEBUG = False
    def __init__(self, monitor, debug = 0):
        self.monitor = monitor
        self.debug = debug
        self.controllers = Dictionary()
        self.controller_lock = Lock()
        super(TransactionManager, self).__init__()
    def _get_controller(self, host, port, protocol):
        location = (host, port)
        self.controller_lock.acquire()
        try:
            if not self.controllers.has_key(location):
                self.controllers[location] = LocationController(
                    self.monitor, host, port, protocol, self.debug)
        finally:
            self.controller_lock.release()
        return self.controllers.get(location)
    def create_transaction(self, request,sid):
        controller = self._get_controller(request.get_host(), 
                                          request.get_port(), 
                                          request.get_type())
        
        if(controller.is_transaction_pending(sid)):
            if self.debug or self.QUEUEDEBUG: 
                msglog.log('broadway',msglog.types.DB,'Already Pending transaction, so not adding transaction. sid=%s' %(sid))
            controller.recruit_and_send()
            return(None)
            
        transaction = Transaction(request,sid=sid)
        
        if self.debug or self.QUEUEDEBUG:
            before = repr(controller)
        controller.add_transaction(transaction)
        if self.debug or self.QUEUEDEBUG:
            after = repr(controller)
            message = 'Controller before and after adding transaction:\n'
            message += '    - Before: %s\n' % (before[1:-1])
            message += '    - After: %s\n' % (after[1:-1])
            msglog.log('broadway', msglog.types.DB, message)
        return transaction