Example #1
0
 def on_exit(server):
     from common.config.conf import config
     from boarpc.url import URL
     from boarpc.registry.registryService import RegistryFactory
     host, port = server.app.cfg.bind[0].split(":")
     registry = RegistryFactory.createRegistry()
     registry.unRegister(URL(config.getConf('rpc', 'protocol', defult='thrift'), host, port))
Example #2
0
class ZkRigster(object):
    PROTOCOL = config.getConf('rpc', 'protocol', defult='thrift')

    def __init__(self, bind):
        host, port = bind.split(":")
        self.url = URL(self.PROTOCOL, host, port)

    def run(self):
        # register to zk
        logger.info("-------register to zk--------")
        registry = RegistryFactory.createRegistry()
        urlSet = set()
        urlSet.add(self.url)
        registry.urlSet = urlSet
        registry.registerAll()
        logger.info(self.url)
        # monitor children process
        while True:
            time.sleep(10)
            providers = registry.getAllProvides()
            if self.url.getHostPort() not in providers:
                # Re-register if lost in the registry
                registry.register(self.url)

    def register_instances(self):
        p = Process(target=self.run, args=())
        p.daemon = True
        p.start()
Example #3
0
    def startWorker(self):
        processes = int(
            config.getConf('rpc', 'processes', multiprocessing.cpu_count()))
        urlSet = set()
        portSet = set()

        # get all endpoints
        endpointSet = self.getAllEndpoints()
        host = NetUtils.getIp()
        for i in range(0, processes):
            # get a port
            port = NetUtils.getFreePort()
            if port in portSet:
                flag = True
                while flag:
                    time.time(5)
                    port = NetUtils.getFreePort()
                    if port not in portSet:
                        break
            portSet.add(port)
            url = URL(self.PROTOCOL, host, port)
            url.setEndpints(endpoints=endpointSet)
            p = Process(target=self.worker, args=(url, ))
            urlSet.add(url)
            url.setProcess(p)
            p.start()
        return urlSet
Example #4
0
 def __init__(self,bind):
     host,port = bind.split(":")
     self.url = URL(self.PROTOCOL, host, port)