Пример #1
0
 def main(cls, args):
     """ generated source for method main """
     GamerLogger.setSpilloverLogfile("spilloverLog")
     GamerLogger.log("Proxy", "Starting the ProxyGamePlayerClient program.")
     if not (len(args)):
         GamerLogger.logError("Proxy", "Usage is: \n\tProxyGamePlayerClient gamer port")
         return
     port = 9147
     gamer = None
     try:
         port = Integer.valueOf(args[1])
     except Exception as e:
         GamerLogger.logError("Proxy", args[1] + " is not a valid port.")
         return
     gamers = Lists.newArrayList(ProjectSearcher.GAMERS.getConcreteClasses())
     gamerNames = ArrayList()
     if len(gamerNames) != len(gamers):
         for c in gamers:
             gamerNames.add(c.__name__.replaceAll("^.*\\.", ""))
     idx = gamerNames.indexOf(args[0])
     if idx == -1:
         GamerLogger.logError("Proxy", args[0] + " is not a subclass of gamer.  Valid options are:")
         for s in gamerNames:
             GamerLogger.logError("Proxy", "\t" + s)
         return
     try:
         gamer = (gamers.get(idx).newInstance())
     except Exception as ex:
         GamerLogger.logError("Proxy", "Cannot create instance of " + args[0])
         return
     try:
         theClient.start()
     except IOException as e:
         GamerLogger.logStackTrace("Proxy", e)
Пример #2
0
 def run(self):
     """ generated source for method run """
     GamerConfiguration.showConfiguration()
     GamerLogger.setSpilloverLogfile("spilloverLog")
     #  Start up the client manager
     self.theClientManager = self.ClientManager(Thread.currentThread())
     self.theClientManager.start()
     #  Start up the input queue listener
     inputQueue = ArrayBlockingQueue(100)
     inputConnectionQueue = ArrayBlockingQueue(100)
     theListener = QueueListenerThread()
     theListener.start()
     while True:
         try:
             #  First, read a message from the server.
             self.notifyObservers(PlayerReceivedMessageEvent(in_))
             GamerLogger.log("Proxy", "[PROXY] Got incoming message:" + in_)
             #  Formulate a request, and see how the legal gamer responds.
             try:
                 legalProxiedResponse = request.process(receptionTime)
             except OutOfMemoryError as e:
                 #  Something went horribly wrong -- our baseline prover failed.
                 System.gc()
                 GamerLogger.logStackTrace("Proxy", e)
                 legalProxiedResponse = "SORRY"
             latestProxiedResponse = legalProxiedResponse
             GamerLogger.log("Proxy", "[PROXY] Selected fallback move:" + latestProxiedResponse)
             if not (isinstance(request, (InfoRequest, ))):
                 #  Update the move codes and prepare to send the request on to the client.
                 self.receivedClientMove = False
                 self.currentMoveCode = 1 + self.theRandomGenerator.nextLong()
                 if isinstance(request, (StopRequest, )) or isinstance(request, (AbortRequest, )):
                     self.theClientManager.expectStop = True
                 #  Send the request on to the client, along with the move code.
                 self.theClientManager.sendMessage(theMessage)
                 if not (isinstance(request, (PlayRequest, ))):
                     self.currentMoveCode = 0L
                 #  the default gamer handle it by switching move code.
                 #  Wait the appropriate amount of time for the request.
                 proxyProcessRequest(request, receptionTime)
             else:
                 self.receivedClientMove = True
             #  Get the latest response, and complain if it's the default response, or isn't a valid response.
             if not self.receivedClientMove and (isinstance(request, (PlayRequest, ))):
                 GamerLogger.logError("Proxy", "[PROXY] Did not receive any move information from client for this turn; falling back to first legal move.")
                 GamerLogger.logError("ExecutiveSummary", "Proxy did not receive any move information from client this turn: used first legal move.")
             #  Cycle the move codes again so that we will ignore any more responses
             #  that the client sends along to us.
             self.currentMoveCode = 0L
             #  And finally write the latest response out to the server.
             GamerLogger.log("Proxy", "[PROXY] Wrote outgoing message:" + out)
             HttpWriter.writeAsServer(connection, out)
             connection.close()
             self.notifyObservers(PlayerSentMessageEvent(out))
             #  Once everything is said and done, restart the client if we're
             #  due for a restart (having finished playing a game).
             if self.needRestart:
                 self.theClientManager.closeClient()
                 self.theClientManager.pleaseStop = True
                 if GamerConfiguration.runningOnLinux():
                     #  Clean up the working directory and terminate any orphan processes.
                     Thread.sleep(500)
                     GamerLogger.log("Proxy", "[PROXY] Calling cleanup scripts.")
                     try:
                         Runtime.getRuntime().exec_("./cleanup.sh").waitFor()
                     except IOException as e:
                         GamerLogger.logStackTrace("Proxy", e)
                     Thread.sleep(500)
                 self.theClientManager = self.ClientManager(Thread.currentThread())
                 self.theClientManager.start()
                 self.theDefaultGamer = RandomGamer()
                 GdlPool.drainPool()
                 SymbolPool.drainPool()
                 GamerLogger.log("Proxy", "[PROXY] Before collection, using " + usedMemoryInMegs + "mb of memory as proxy.")
                 while i < 10:
                     System.gc()
                     Thread.sleep(100)
                     i += 1
                 usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()
                 usedMemoryInMegs = usedMemory / 1024.0 / 1024.0
                 GamerLogger.log("Proxy", "[PROXY] After collection, using a non-transient " + usedMemoryInMegs + "mb of memory as proxy.")
                 print "Cleaned up completed match, with a residual " + usedMemoryInMegs + "mb of memory as proxy."
                 self.needRestart = False
         except Exception as e:
             GamerLogger.logStackTrace("Proxy", e)
             self.notifyObservers(PlayerDroppedPacketEvent())
         except Error as e:
             GamerLogger.logStackTrace("Proxy", e)
             self.notifyObservers(PlayerDroppedPacketEvent())