class LockServiceHandler:
    def __init__(self):
        self.queue = Queue()
        self.lc = LockContainer(self.queue)
        self.lc.setDaemon(True)
        self.lc.start()
        self.lg = LockSeverDiag(self.lc)
        self.lg.setDaemon(True)
        self.lg.start()
        self.clients = Clients(self.queue)
        self.clients.setDaemon(True)
        self.clients.start()

    def __del__(self):
        self.clients.stop()

    def lockOp(self, clientId, lockCmd):
        if not self.clients.is_registered(clientId):
            return StatusMsg.CLIENT_NOT_REGISTERED
        if lockCmd.op == LockOperation.UNLOCK:
            logging.debug('Unlock ' + lockCmd.lockId + ' by ' + clientId)
            return self.lc.unlock(clientId, lockCmd.lockId)
        return self.lc.add_lock(clientId, lockCmd.lockId, lockCmd.op)

    def registerClient(self, clientId):
        self.clients.add_client(clientId)
        return StatusMsg.SUCCESS

    def sendHeartBeat(self, clientId):
        if not self.clients.is_registered(clientId):
            return StatusMsg.CLIENT_NOT_REGISTERED
        self.clients.heartbeat(clientId)
        return StatusMsg.SUCCESS

    def reRegisterLocks(self, clientId, locks):
        if not self.clients.is_registered(clientId):
            return StatusMsg.CLIENT_NOT_REGISTERED
        for lock in locks.locks:
            self.lc.add_lock(clientId, lock.lockId, lock.op)
        return StatusMsg.SUCCESS

    def getLockDetails(self, lockid):
        return self.lc.getLockDetails(lockid)

    def getLiveClients(self):
        return self.clients.getClients()

    def unRegisterClient(self, clientId):
        return self.clients.unRegisterClient(clientId)

    def shutDown(self):
        self.clients.stop()
        self.lc.stop()
        self.lg.stop()
class LockServiceHandler:
    def __init__(self):
        self.queue = Queue()
        self.lc = LockContainer(self.queue)
        self.lc.setDaemon(True)
        self.lc.start()
        self.lg = LockSeverDiag(self.lc)  
        self.lg.setDaemon(True)
        self.lg.start()
        self.clients = Clients(self.queue)
        self.clients.setDaemon(True)
        self.clients.start()  

    def __del__(self):
        self.clients.stop()

    def lockOp(self, clientId, lockCmd):
        if not self.clients.is_registered(clientId):
            return StatusMsg.CLIENT_NOT_REGISTERED
        if lockCmd.op == LockOperation.UNLOCK:
            logging.debug('Unlock ' + lockCmd.lockId + ' by ' + clientId)
            return self.lc.unlock(clientId, lockCmd.lockId)
        return self.lc.add_lock(clientId, lockCmd.lockId, lockCmd.op) 

    def registerClient(self, clientId):
        self.clients.add_client(clientId)
        return StatusMsg.SUCCESS

    def sendHeartBeat(self, clientId):
        if not self.clients.is_registered(clientId):
            return StatusMsg.CLIENT_NOT_REGISTERED
        self.clients.heartbeat(clientId)
        return StatusMsg.SUCCESS

    def reRegisterLocks(self, clientId, locks):
        if not self.clients.is_registered(clientId):
            return StatusMsg.CLIENT_NOT_REGISTERED
        for lock in locks.locks:
            self.lc.add_lock(clientId, lock.lockId, lock.op) 
        return StatusMsg.SUCCESS

    def getLockDetails(self, lockid):
       return self.lc.getLockDetails(lockid) 

    def getLiveClients(self):
        return self.clients.getClients()

    def unRegisterClient(self, clientId):
        return self.clients.unRegisterClient(clientId)
    
    def shutDown(self):
        self.clients.stop()
        self.lc.stop()
        self.lg.stop()
Esempio n. 3
0
def main():
    init_logging('/tmp/lockserver.log')
    ebus = eventbus()
    clients = Clients(ebus)
    clients.setDaemon(True)
    clients.start()
    lc = LockContainer(ebus)
    ebus.register_consumer(lc, common.LOCKOP_TOPIC)
    ebus.register_consumer(lc, common.UNREGISTER_TOPIC)
    ebus.register_consumer(clients, common.RESPONSE_TOPIC)
    f = DistComFactory(ebus)
    f.protocol = DistLockComm
    reactor.listenTCP(8000, f)
    reactor.run()