Exemplo n.º 1
0
 def connectToClusterServer(self, certificatePath, clusterServerIP,
                            clusterServerListenningPort,
                            statusDBUpdateInterval):
     """
     Establishes a connection with the cluster server.
     Args:
         certificatePath: the server.crt and server.key directory path.
         clusterServerIP: the cluster server's IPv4 address
         clusterServerListenningPort: the cluster server's listenning port.
         statusDBUpdateInterval: the status database update interval (in seconds)
     Returns:
         Nothing
     """
     self.__manager = NetworkManager(certificatePath)
     self.__manager.startNetworkService()
     callback = _ClusterServerEndpointCallback(self)
     # Connect to the main server
     self.__clusterServerIP = clusterServerIP
     self.__clusterServerPort = clusterServerListenningPort
     self.__manager.connectTo(clusterServerIP, clusterServerListenningPort,
                              5, callback, True)
     while (not self.__manager.isConnectionReady(
             clusterServerIP, clusterServerListenningPort)):
         sleep(0.1)
     # Create the packet handler
     self.__pHandler = ClusterServerPacketHandler(self.__manager)
     # Create the update thread
     self.__updateRequestThread = StatusDatabaseUpdateThread(
         _ClusterServerEndpointUpdateHandler(self), statusDBUpdateInterval)
     # Start it
     self.__updateRequestThread.start()