Exemplo n.º 1
0
    def __init__(self, config_file):
        u"""Cluster 抽象"""
        self.config_file = config_file
        self.config = Config(config_file)
        self.context = Context(self.config.parse_refer(),
                               self.config.parse_registry())

        self.clients = {}
        self.sem = BoundedSemaphore(1)
Exemplo n.º 2
0
class Cluster(object):
    def __init__(self, config_file):
        u"""Cluster 抽象"""
        self.config_file = config_file
        self.config = Config(config_file)
        self.context = Context(self.config.parse_refer(),
                               self.config.parse_registry())

        self.clients = {}
        self.sem = BoundedSemaphore(1)

    def get_client(self, service):
        if service not in self.clients:
            self.sem.acquire()
            if service not in self.clients:
                self.clients[service] = Client(self.context, service)
            self.sem.release()
        return self.clients[service]
Exemplo n.º 3
0
def new_server(config_file):
    u"""从配置文件生成server"""
    config = Config(config_file)
    context = Context(config.parse_service(), config.parse_registry())
    return Server(context)