def convertList(cls, tokens): """ generated source for method convertList """ contents = ArrayList() tokens.removeFirst() while not tokens.getFirst() == ""): contents.add(cls.convert(tokens)) tokens.removeFirst() return SymbolPool.getList(contents)
def toSymbol(self): """ generated source for method toSymbol """ infoList = ArrayList() if self.name != None: infoList.add(self.getKeyValueSymbol("name", self.name)) if self.status != None: infoList.add(self.getKeyValueSymbol("status", self.status)) if self.species != None: infoList.add(self.getKeyValueSymbol("species", self.species)) return SymbolPool.getList(infoList)
def convertAtom(cls, tokens): """ generated source for method convertAtom """ return SymbolPool.getAtom(tokens.removeFirst())
def getKeyValueSymbol(self, key, value): """ generated source for method getKeyValueSymbol """ keySymbol = SymbolPool.getAtom(key) valueSymbol = SymbolPool.getAtom(value) return SymbolPool.getList([None]*)
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())