示例#1
0
    def __init__(self, verbose=False):
        # TODO: add uniq id
        self.verbose = verbose
        uniq = Uniq()
        self.uniqid = uniq.getid(uniq.WORKER)

        # zookeeper connection
        zb = ZooBorgFactory(Configuration.getworker()['zookeeper']['mockmode'],
                            Configuration.getworker()['zookeeper']['ip'],
                            Configuration.getworker()['zookeeper']['port'])
        addconf = zb.getConf(ZooConst.WORKER)
        con_str = addconf['broker']['connectionstr']
        zb.register(ZooConst.WORKER, self.uniqid, self.zoo_conf_changed)
        self.worker = MajorDomoWorker(con_str, "echo", self.verbose)

        # init mongodb pool
        self.mp = MongoPool(Configuration.getworker()['mongo']['host'],
                            Configuration.getworker()['mongo']['port'],
                            Configuration.getworker()['mongo']['db'],
                            Configuration.getworker()['mongo']['maxcon'])
示例#2
0
    def __init__(self, maxconnection=10):
        # copie de l'état lors de l'initialisation d'une nouvelle instance
        self.__dict__ = self.__shared_state
        if not(self.initialized):
            #N MajorDomoClient
            #print "INIT ConnectionPool"

            zb = ZooBorgFactory(Configuration.getclient()['zookeeper']['mockmode'],
                                Configuration.getclient()['zookeeper']['ip'],
                                Configuration.getclient()['zookeeper']['port'])


            zooconf = zb.getConf(ZooConst.CLIENT)
            connection_str = zooconf['broker']['connectionstr']
            uniq = Uniq()
            for _ in range(1, maxconnection):
                conn = MajorDomoClient(connection_str, False, self)
                self.__availableconnection.append(conn)
                #register connexion
                zb.register(ZooConst.CLIENT, uniq.getid(uniq.CLIENT), self._zconfchanged)
            self.initialized = True
示例#3
0
 def __init__(self, verbose=False):
     """Initialize broker state."""
     self.verbose = verbose
     self.services = {}
     self.workers = {}
     self.waiting = []
     self.heartbeat_at = time.time() + 1e-3 * self.HEARTBEAT_INTERVAL
     self.ctx = zmq.Context()
     self.socket = self.ctx.socket(zmq.ROUTER)
     self.socket.linger = 0
     self.poller = zmq.Poller()
     self.poller.register(self.socket, zmq.POLLIN)
     logging.basicConfig(format="%(asctime)s %(message)s",
                         datefmt="%Y-%m-%d %H:%M:%S",
                         level=logging.INFO)
     uniq = Uniq()
     self._uniqid = uniq.getid(uniq.BROKER)
     zb = ZooBorgFactory(Configuration.getbroker()['zookeeper']['mockmode'],
                         Configuration.getbroker()['zookeeper']['ip'],
                         Configuration.getbroker()['zookeeper']['port'])
     addconf = zb.getConf(ZooConst.BROKER)
     con_str = addconf['bindstr']
     zb.register(ZooConst.BROKER, self._uniqid, self.zoo_conf_changed)
     self.bind(con_str)