예제 #1
0
    def joinServer(self, id):
        # start replica server
        p = Process(target=spinUpServer, args=(self.openPort,))
        p.start()

        time.sleep(self.wait) # wait for server.serve() [messy]

        # set up RPC to replica server
        transport = TSocket.TSocket('localhost', self.openPort)
        transport = TTransport.TBufferedTransport(transport)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        replica = Replica.Client(protocol)

        transport.open()
        replica.setID(id)
        # connect everyone
        for sid, server in self.stubs.items():
            # stubs contains replicas and clients, only connect new server to
            # existing servers
            if sid not in self.replicas:
                continue
            self.transports[sid].open()
            server.addConnection(id, self.openPort)
            self.transports[sid].close()
            replica.addConnection(sid, self.ports[sid])
        transport.close()

        self.ports[id] = self.openPort
        self.procs[id] = p
        self.replicas.add(id)
        self.stubs[id] = replica
        self.transports[id] = transport
        self.openPort += 1
예제 #2
0
    def addConnection(self, id, port):
        transport = TSocket.TSocket('localhost', port)
        transport = TTransport.TBufferedTransport(transport)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        replica = Replica.Client(protocol)

        transport.open()
        self.reachable.add(id)
        self.stubs[id] = replica
        self.transports[id] = transport
        transport.close()

        return id in self.reachable